I have a sorted list of numbers. I want to search the array for a number (lets call it searchVal). So the line of code below works fine if the number is in the array.
var sPos = $.inArray(searchVal, MyArray);
However if it is not in MyArray I want to select the next biggest number, i.e
I'm searching for 8 in the list below I would like it to return 10.
4, 5, 6, 10, 11
I am new to javascript and wondering what the best way to achieve this is? I have seen a filter could be used where any number >= to 8 is returned and then take the min number from this filtered list. Or is this a case when I should make use of the reduce function?