My code doesn't work but i am confidence in my code ,what is the mistake here?

My code doesn't work but i am confidence in my code ,what is the mistake here?
0.0 0

#1

Tell us what’s happening: i want return the index of the a number (num) in the sorted array (arr)

Your code so far

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr=arr.sort();
  for(var i=0;i<arr.length;i++){
    if(arr[i]==num){
      return i-1;
    }
    else if(arr[i]>num){
      return i;
    }
  }
  
}

getIndexToIns([40, 60], 50);

Your browser information:

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

Link to the challenge:


#2

Your sort is not working as you think it is. Review the documentation for the sort function and read the section concerning sorting numbers.