main.js
1
2
3
4
5
6
7
8
9
10
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var times = arr.length; // runs the for loop once for each thing in the array
  var count = 0; 
  for (i=0;i<times;i++){
    if(num>arr[i]){count++;} } // counts how many array numbers are smaller than num
    return count; // the above equals num's position in a sorted array
}

getIndexToIns([40, 34, 44, 60], 50);
Native Browser JavaScript