My es6 solution

Continuing the discussion from A Better Solution? - Diff Two Arrays:

const diffArray = (arr1, arr2) => {
    return [
        ...arr1.map(x => !arr2.includes(x) ? x : null), 
        ...arr2.map(y => !arr1.includes(y) ? y : null)
      ].filter(i => i !== null)
  }
  
  console.log(diffArray([1, "calf", 3, "piglet"], [1, "calf", 3, 4]));

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

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