Tell us what’s happening:
Hello all, I have managed to get this code to somewhat work for about half the challenges required but a lot of them return the wrong answer. What am I missing here?
Your code so far
function getIndexToIns(arr, num) {
arr.sort(function (a, b){return a - b})
for (var i = 0 ; i < arr.length ; i++) {
if (num < arr[i]) {
return arr.indexOf(num);
}
}
}
console.log(getIndexToIns([40, 60], 50));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0
.
Challenge: Where do I Belong
Link to the challenge: