Sorted Union - can't use arr.length?

Tell us what’s happening:
While I’m able to pass to test. I was frustrated and stuck for a long time about one problem. On the first for loop to put all arguments into one new Array. When I initially used k< arr.length, it does not work on all cases. Then I found out the arr.length shows a weird result.

For example:
uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]) <-- arr.length is actually 3 but not 4. While arguments.length is 4 correctly.

uniteUnique([1, 2, 3], [5, 2, 1]) <-- again the arr.length is 3 not 2

I would like to know why arr.length is not equalivilant to arguments.length in all cases. Isn’t arr the function’s parameter to the arguments?

Your code so far


function uniteUnique(arr) {
  let newArr = []
  console.log(arr.length);
  for (let k = 0; k < arguments.length; k++){
    newArr.push(...arguments[k]);
    console.log(newArr);
  }

  for (let i = 1; i < newArr.length; i++)
{
    for (let y = 0; y < i; y++){
      console.log(newArr[i] + " vs "+ newArr[y]);
      console.log(newArr[i] === newArr[y]);
      if (newArr[i] === newArr[y]){
        newArr.splice(i , 1);
        i--;
        console.log(newArr);
        console.log("deleted");
        console.log();
        }
      else {
        console.log(newArr);
        console.log("next");
        console.log();
      }
    }
}
  return newArr;
}

console.log(uniteUnique([1, 2, 3], [5, 2, 1]));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sorted-union

I’m guessing it’s because arr refers to the first argument ([1, 2, 3]), while arguments refers to the whole arguments object. I’m not sure why the function was declared with arr parameter, but you can pretty much just ignore arr and work with the arguments object.

Oh, I see! This makes sense as both case’s first array has item length of 3. I think the challenge designed that way so we can learn how to use arguments. I’ve seen only one parameter entry provided with multiple inputs in other challenges as well. Thanks!