if the number is bigger then the biggest number of the array, test fails…

Help is appreciated.

Thanks!!

**Your code so far**

```
function getIndexToIns(arr, num) {
const sortedArr = arr.sort((a, b) => a - b);
if (sortedArr.length == 0 || num < sortedArr[0]) {
return 0; }
for (let i = 0; i < sortedArr.length - 1; i++) {
if (num == sortedArr[i]) {
return sortedArr.indexOf(sortedArr[i]);
}
if (num > sortedArr[i] && num < sortedArr[i + 1]) {
return sortedArr.indexOf(sortedArr[i + 1]);
}
}
return sortedArr[sortedArr.length];
}
getIndexToIns([40, 60], 50);
```

**Your browser information:**

User Agent is: `Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0`

.

**Challenge:** Where do I Belong

**Link to the challenge:**