Where do I Belong? Unknown error

I get the error wrappedCompareFn is not a function. What kind of error is this?
Here is my code:

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

getIndexToIns([40, 60], 50);

Haiiiyo, it’s throwing that error because of arr.sort(arr). The error says TypeError: wrappedCompareFn is not a function because the .sort() method accepts a callback function to sort item in the array, but you are supplying an array/object as an argument.

The second .sort() does contain a function but it still won’t work because you need to return whether either true or false depending on how you want to sort the array. Please have a look at the MDN documentation for Array.prototype.sort(). You will likely bump into further problems with .indexOf—read through the examples in the MDN documentation for that, too. :slight_smile:

Thanks for the tip, it’s allways nice to receive advice since i’m just a beginner on this. You on the other hand seem to know the game very well :slight_smile: . Congrats

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

It’s absolutely no problem. I can assure you that I made similar mistakes like that three months ago—as long as you like coding just keep at it and you will be fine. :slight_smile:

Good luck!

Thanks, I have started in january on freecodecamp and not been so active now due to other professional things, and also as I have been also blocked on several challenges.