I am wrong about this problem?

I am wrong about this problem?
0

#1

I was requested to rite a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays. In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.

The problem es that the function call have three arguments and function only receives one. My question is;

Is the function header right?

If is right how I could do to get all the info because actually on can access the first array. Here the code:

function uniteUnique(arr) {
  var newArr=[];
  var args = Array.from(arr);
  
  for(i=0;i<arr.length;i++){
    if(Array.isArray(arr[i])){
      for(j=0;j<arr[i].length;j++){
        if(!newArr.includes(arr[i][j])){
          newArr.push(arr[i][j]);
        }
      }
    }else{
      newArr.push(arr[i]);
    }
  }
  return newArr;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);

#2

You could technically not define any function parameters for uniteUnique. You will need to take advantage of the arguments object in JavaScript to access one, two, three,…many extra values passed into the function. When you specifically define a parameter (like arr) in the above, then it represents the first value passed into the function.


#3

Thanks. I understand that, but ther’s no problem if I take out the argument of uniteUnique()?


#4

The arr parameter is just a placeholder that you could use. You can leave it out all together and just use the arguments object. See below for an example of working with the arguments object.

function myFunction() {
  var args = Array.from(arguments); // now args is an array
  for (var i in args) {
    console.log(args[i])
  }
}
myFunction('one','two','three','four');

The above function call produces:

one
two
three
four


#5

Thanks for your help I am on the way to resolve the problem. Again thanks a lot.