Error from JavaScript .sort() and .indexOf() methods

Tell us what’s happening:
I keep getting this error, what’s wrong with my code

getIndexToIns([3, 10, 5], 3)

should return

0
getIndexToIns([5, 3, 20, 3], 5)

should return

2
getIndexToIns([2, 20, 10], 19)

should return
``
2

getIndexToIns([2, 5, 10], 15)

should return

3

**Your code so far**
      
```js
function getIndexToIns(arr, num) {
arr.push(num);
arr.sort();
return arr.indexOf(num);
}
getIndexToIns([40, 60], 50);

Challenge: Where do I Belong

Link to the challenge:

check the value of arr after this line for the failed tests

Sort does not do what you are expecting by default when it comes to numbers.
The default sort is always alphabetical… even when the array has numbers in it.

Try use it like this:

arr.sort((a, b) => a - b);

The callback function(a, b) { return a - b; } is the way to use Array.sort when you are intending to sort by numeric value.

Just as a side note.
This is a classic example of how our non-empirical assumptions may lead to bugs or unexpected results.
Always read the docs for a function/method/library/api you have not built yourself as most of the time behaves differently than you expect.
I have done this mistake way too many times.