What is the most effective to map ranges using Arrays in JavaScript?
I have this:
var def = [70,200,1000];
And an array of possible numbers, say:
var n = [23,45,74,120,240,800,1204,2000];
Now, how can I extract the closest value from n that matches the values from def?
In the example above, I would get [74,240,800]. I hope I make myself clear…
http://jsfiddle.net/8bY2M/
Note that this will go with the larger value in the event of two matches. (i.e. if you are trying to match 70, and n contains 66 and 74, this will match it with 74)