Basic Algorithm Scripting - Where do I Belong

Working through the problem statement and used the below code; when the test is ran, some of the requirements could be passed while a few couldn’t. Can anyone explain the reason so please?

e.g. - getIndexToIns([3, 10, 5], 3) does not return the value 0
getIndexToIns([2, 5, 10], 15) does not return the value 3

function getIndexToIns(arr, num) {
  return arr
    .concat(num)
    .sort()
    .indexOf(num);
}

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/106.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Where do I Belong

Link to the challenge:

You need to research the sort method a bit more. You will need to use a compare function to properly sort the numbers.