I tested the code manually and it outputs the correct values
I do not know why my solution is not correct so far
function getIndexToIns(arr, num) {
let newarr = arr.sort();
let result=0;
for(let index in arr){
if(arr[index]>=num){
result= index
return result
}
}
}
console.log(getIndexToIns(
[10, 20, 30, 40, 50], 30));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.
Other than that, you have an issue with your sort method. By default, it sorts numbers as strings so it is not sorting the way you think it is. If you look in the docs you will find a discussion of how to deal with numbers.
Other than that, you also have the issue of what to do if the for loop finishes and no element is found greater than num. In other words, what if it is supposed to go at the end? What are you returning in that case?
thank you for your help this is the first exercise within the track
where I face comptability issues with my code
i have edited my forloop and sort method and what to do when the loop is over