function getIndexToIns(arr, num) {
// Find my place in this sorted array.
var sorted = arr.sort(function(a, b){return a-b});
for(var i=0; i<sorted.length; i++){
if(num > sorted[sorted.length-1]){
return sorted.length;
}
if(sorted[i] >= num){
return i;
}
}
}
getIndexToIns([5, 3, 20, 3], 5);
No comments:
Post a Comment