score:0

Accepted answer

You're getting NaN because of the following:

var index = dateArray.indexOf('a date that does not exist')   // -1
var el = cumulativeFrequencyArray[index]                      // undefined 
thousandSeparator(el)     // 'NaN' note that it's a string 'NaN', not the numeric NaN

You should do a linear search until the element is found or a greater date is found instead of indexOf, I'd suggest parsing the dates to numbers instead of dealing with them as strings


Related Query

More Query from same tag