Where Do I Belong(Problem)

Its returning the desired output but not passing.

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  let pos
  let sorted = arr.sort()
  //console.log( sorted.length)
  for(let i = 0;i<sorted.length;i++){
    if(arr[i] === num){
      pos = arr.indexOf(arr[i])
  return pos;

console.log(getIndexToIns([40, 60], 50));

I think there is an issue with the fact that you are using the default behaviour of sort(), check what happens if you try to sort like that an array like [1, 2, 3, 11, 21, 31] (the result of the method here is [1, 11, 2, 21, 3, 31] - this is because as default behaviour the sort method convert everything to string and order them by Unicode point value)

Also, you don’t need the loop, think of how indexOf() works

The reason is ,its considering 10 as 1 or 0 ,which are always first in any sorted array,so the array

arr = [10,2,5]//is sorting but returning the same [10,2,5]

its even considering 1000 as 1 or 0 and printing [1000,2,5] as the sorted array.

Yeah, the issue was that the default behaviour is being used, not in the default behaviour itself - I think I wrote it badly, let me edit that post…