Return indexOf num

Tell us what’s happening:

hello! I feel I’m very close to solving this algorithm and wanted to ask where I was going wrong/How to ensure I am inserting it into the correct place within the arr. I want it to check every index until it recognizes that (num > arr[i]) then insert itself into the array.

Thank you!

Your code so far


function getIndexToIns(arr, num) {
arr.sort();
for (let i  = 0; i < arr.length; i++) 
  if (num > arr[i]) {
    arr.push(num)
  }

return arr.indexOf(num);
}

console.log(getIndexToIns([40, 60], 50));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36.

Challenge: Where do I Belong

Link to the challenge:

this is not doing what you think, even if you will see it only with an array like [1,11,4,12]

add console.log(arr) below this line

and also add the same line after your loop