Intermediate Algorithm Scripting - Sorted Union

My code is returning an undefined in its array. Not sure why. Any ideas?

Your code so far

function uniteUnique(arr,arr2,arr3) {
  let array=arr.concat(arr2,arr3);
  let filteredArray=array.filter(function(item,pos){
    return array.indexOf(item)==pos
  return filteredArray

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/ Safari/537.36

Challenge: Intermediate Algorithm Scripting - Sorted Union

Link to the challenge:

Well, it’s because you’ve created a function which takes three arguments but then only supplied two arguments when you’ve called it. So the third argument is returning as undefined.

You may want to consider using the arguments object. That’s one way of approaching the problem of an unknown number of arguments being passed to a function.

Oh I see, thanks thanks.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.