Just a syntax question

Tell us what’s happening:
Solved the challenge but looking at other solutions found this:

what are the dots before diff function for?

//f. return itemsPresentOnlyInOneOfTheArrays

function diffArray(arr1, arr2) {

  return [...diff(arr1, arr2), ...diff(arr2, arr1)];

  function diff(a, b) {

    return a.filter(item => b.indexOf(item) === -1);

  }

}

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

Your code so far


function diffArray(arr1, arr2) {
var newArr = [];
newArr = arr2.filter(item => arr1.indexOf(item) == -1)
.concat(arr1.filter(item => arr2.indexOf(item) == -1))
return newArr;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 OPR/65.0.3467.62.

Challenge: Diff Two Arrays

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

1 Like