Sorted Union - can't filter this out

Tell us what’s happening:
Can’t get filtered array - maybe smth wrong with parameters

Your code so far


function uniteUnique(arr, ...restArr) {
  let arno = arr;
  let rear = restArr[0].concat(restArr[1]);//rests in one-dimensional array
  function check(arno, rear) {//filter items which are not in first array
    return rear.filter(item => arno.includes(item));
  }
  let narr = arno.concat(rear);//merge first array and filtered second array
  return narr;
}

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

Your browser information:

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

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

as a starting point, you define a function check but never use it from what I can see.

1 Like

Thanks, i did it!

function uniteUnique(arr, ...restArr) {
  let arno = arr;
  let rear = [];
  for (var i = 0; i < restArr.length; i++) {
   rear = rear.concat(restArr[i]);//rests in one-dimensional array
  };
  function check(par1, par2) {//filter items which are not in first array
    return rear = par2.filter(item => !par1.includes(item));
  };
  check(arno, rear);
  let narr = arno.concat(rear);//merge first array and filtered second array
  return narr;
}

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

congrats dude. Can’t beat a second pair of eyes :slight_smile: