Diff Two Arrays -- Why Isn't Concat & Filter Working?

I am working back through the intermediate JS algorithms section (trying to get enough repetition that they all seem easy). The following answer is, I thought, the one I had used a previous time.

function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  newArr = arr1.concat(arr2);
  return newArr.filter(function (item,pos) {
    return newArr.indexOf(item) == pos;

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

But it isn’t working. Looking at the browser console, I’m getting the following error:

Source map error: request failed with status 404 Resource URL: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/diff-two-arrays Source Map URL: normalize.min.css.map

Does anyone have any idea what I need to do or what the problem is?

Not sure how you passed last time.

But what your code is doing is basically removing duplicates. Since you know duplicate values, only return an array of values that doesn’t have duplicates in other array.

1 Like