My code WORKS and it works better because it can sort and give the index of even more than just one argument (num, num_1...num_n). Try it. But compiler doesn't let me pass to the new challenge

My code WORKS and it works better because it can sort and give the index of even more than just one argument (num, num_1...num_n). Try it. But compiler doesn't let me pass to the new challenge
0

#1

Tell us what’s happening:

Your code so far



function getIndexToIns(arr, num) {

  var argomenti = [];
  var indexArgs = [];
  
  
  //push the arguments (no the arr) into an array named argomenti []
  
  for(var i = 1; i < arguments.length; i++)
    {
      argomenti.push(arguments[i]);
    }
  
  
 //sort the array ARR's value from minor to max 
  arr = arr.sort(function (a, b)
                {
    return a - b;
  });
  
  
  //push the values of ARGOMENTI[] into ARR
  
   for(var n = 0; n < argomenti.length; n++)
     {
       arr.push(argomenti[n]);
     }
  
 //sort the array ARR's value from minor to max 
  arr = arr.sort(function (a, b)
                {
    return a - b;
  });
  
  
  //for cycle that return an array INDEXARGS with the index of the new arguments add and sort previously 
  for(var x = 0; x < argomenti.length; x++)
    {
      indexArgs.push(arr.indexOf(argomenti[x]));
    }
  
  //transform the array INDEXARGS into string of number
  indexArgs = indexArgs.join(" "); 
  
 return indexArgs;
}

getIndexToIns([2, 5, 10], 15);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:


#2

The reason your solution does not pass, is because you are returning a string instead of a number. Since after the last for loop, indexArgs has only one element (the actual number you need to return), you could replace all of the following:

  //transform the array INDEXARGS into string of number
  indexArgs = indexArgs.join(" "); 
  
return indexArgs;

with

return indexArgs[0]; // this returns the first element of the array

#3

'2' is not equal to 2, etc.