Here is the problem, Basic Algorithm Scripting: Where do I Belong

Here is my code,

```
function getIndexToIns(arr, num) {
var sortArr = arr.sort(function(a,b){return a-b});
var perfectNum = 0;
for(let i=0; i < sortArr.length; i++){
if(arr[i] >= num){
perfectNum = i;
break;
} else if(num > sortArr[arr.length-1]){
perfectNum = arr.length;
}
}
return perfectNum;
}
```

Is my way of solving this issue is efficient? Feel free to share if you have any better process?

Some Useful link: