Where do I belong

Hi there. I am a bit stuck. Would like an input, where is the error. Thanks

function getIndexToIns(arr, num) {

  let sorting = arr.sort();
  for (let i = 0; i < sorting.length; i++) {
    if (sorting[i] <= num) {
      return sorting.indexOf(sorting[i]);
    if (num > sorting[i]) {
      return sorting.length;
    if (sorting.length === 0) {
      return 0;

This is part of your problem.

If I have the following:

const arr = [3, 10, 5];

What does arr look like after the above code executes?

According to my limited knowledge should be [3, 5, 10].

Test the code and see.

it is [ 10, 3, 5 ]. why???

Read all about the sort method and why you need to use a compare function.

I think I understood. I just read that numbers are considered strings of characters, so 10 comes before 3 because 1 < 3. Damn, always the syntax…
Thank you for asking me to check, I would had never imagined that.

Once you implement the correct sort function, you need to realize that as soon as a return statement is executed, the function exits regardless if the for loop is complete. Currently, your for loop only ever iterates over the first element before exiting and returning a value.

FYI - This challenge can actually be solved without sorting the array at all, but most users do use the sort method as part of a solution.