Hi,
My code seems fine, but Free Code Camp tells me it is not good for values
getIndexToIns([2,5,10],15);
My code returns 3 which is correct, but Free Code Camp says it should return the number 3 for these values, which it does!
What is wrong with my code?
Regards,
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.sort();
for (var i=0;i<arr.length;i++) {
if (arr[i] >= num) {
num= i;
return num;
}
else if (num>= arr[i]) {
return (arr.length);
}
}
}
getIndexToIns([2,5,10],15);