Tell us what’s happening:
What is the issue in my code? It is not passing the single test.
Your code so far
function getIndexToIns(arr, num) {
arr.sort((a, b) => a - b);
for(let elem in arr){
if(arr[elem] >= num)
{
// console.log(elem)
return elem;
}
}
// console.log(arr.length);
return arr.length;
}
console.log(getIndexToIns([10, 20, 30, 40, 50], 30));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Where do I Belong
Link to the challenge: