Diff Two Arrays using concat and filter methods

Diff Two Arrays using concat and filter methods
0

#1

Tell us what’s happening:
I’ve used the concat method to join both of the arrays. I’m planning on using filter to return true only if the value is unique and return false when the value is duplicated within the array. I can’t seem to figure out how to do that though. any ideas would help.

Your code so far


function diffArray(arr1, arr2) {
  var newArr = [];
  return arr1.concat(arr2).fiter(value=> )
  
}

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

Your browser information:

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

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


#2

Think about how you could use indexOf or includes inside the filter. indexOf returns the actual index (0 or greater) if a specified slement is found in an array or -1 if not found. includes returns true if a specified element is found in an array or false if it is not found


#3

That was such great hint however, I am getting a arr1.concat… .filter isn’t a function error. Do you know why and does my logic check out?

function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
return arr1.concat(arr2).fiter(function(value){
if(arr1.includes(value)&&arr2.includes(value))
{return false;}
else {
return value;
}
});
}

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


#4

Because you have a typo on this line.


#5

Thanks so much for your help and patience