Tell us what’s happening:
I already checklist all other issues, but these two still give me wrong.
why false condition gives 3 as a return?
I got error like this:
// running tests
getIndexToIns([2, 5, 10], 15)
should return 3
getIndexToIns([], 1)
should return 0
// tests completed
Your code so far
function getIndexToIns(arr, num) {
arr = arr.sort(function(a, b){
return a - b;
});
for (let i = 0; i < arr.length; i++){
if (arr[i] >= num){
return i;
}
}
return num;
}
getIndexToIns([40, 60], 50);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
.
Challenge: Where do I Belong
Link to the challenge: