I can’t find a mistake in my code, don’t know why it doesn’t work. I will be very thankful for your ideas
Your code so far
function getIndexToIns(arr, num) {
var newArr = arr.sort();
var ind = newArr.findIndex(i => i > num);
return ind >= num ? ind : ind++;
}
getIndexToIns([40, 60], 50);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.
First is your sort function. When you are sorting numbers in an array, default sort function won’t sort correctly because it’s sorting by unicodes. You want to pass in a call back function there.
Second is your findIndex function. If the condition doesn’t meet, it returns false which is index -1. So incrementing by +1 won’t pass one of the test cases.