So my solution for this uses helper function to remove duplicates inside one array.
Without such function I am getting results like:
[1, 1, 5, 4]//instead of expected [1, 5, 4]
I am confused by solution 3 from the hint page.
They are using diff() helper function, it doesn’t remove duplicates inside one array. I am using somewhat similar function in my approach. Below couple of test cases to show what I mean
const diffFromHint = (arr1, arr2) => [
...arr1.filter(e => !arr2.includes(e)),
...arr2.filter(e => !arr1.includes(e))
];
console.log(diffFromHint([1, 2, 3], [5, 2, 1, 4]));//[ 3, 5, 4 ]
console.log(diffFromHint([1, 2, 3, 3], [5, 2, 1, 4]));//[3, 3, 5, 4]
Yet somehow the whole solution 3 is working just fine and passing the tests. I guess I don’t know much about sets, but I can’t figure out what exactly I am missing here…