Tell us what’s happening:
The challenge fail me on 2 tests:
getIndexToIns([5, 3, 20, 3], 5)
should return 2
.
getIndexToIns([2, 20, 10], 19)
should return 2
.
I tried copying the code in a console and run it, and it returns what is expected in the test. And weird enough is that other tests pass. I can’t see what the output the tests see.
Can some one help to take a look at my code? If that’s alright, how should I debug why the tests are unhappy?
Your code so far
function getIndexToIns(arr, num) {
arr.sort((a, b) => a > b);
var minIndex = 0;
for (var i = 0; i < arr.length; ++i) {
if (arr[i] < num) {
minIndex = i + 1;
} else {
break;
}
}
return minIndex;
}
getIndexToIns([40, 60], 50);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8
.
Link to the challenge:
https://www.freecodecamp.org/challenges/where-do-i-belong