I have created a logic of my own. My question is why result is returning -1. Whats wrong in my logic. I know problem is in indexOf line

**Mycode so far**

```
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
var a;
var sortedarr=arr.sort(function(a,b){
return a-b;
});
var aftersort=sortedarr.map(function(val){
return val-num;
});
var result=aftersort.indexOf(Math.min.apply(Math,a));
return result;
}
getIndexToIns([3, 10, 5], 3);
```

**Your browser information:**

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36`

.

**Link to the challenge:**

https://www.freecodecamp.org/challenges/where-do-i-belong