Can someone out there help me refractor the “Where do I belong” algorithm?

**Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number.**

Here is my code:

function getIndexToIns(arr, num) {

// Find my place in this sorted array.

arr.push(num);

arr.sort(compareNumbers);

for(var i=0; i<arr.length; i++){

if(arr[i]===num){

return i;

}

}}

function compareNumbers(a, b){

return a-b;

}

getIndexToIns([40, 60], 50);

Thanks in advance!