diff --git a/snippets/symmetricDifference.md b/snippets/symmetricDifference.md index 6f13806e4..1f76f8f25 100644 --- a/snippets/symmetricDifference.md +++ b/snippets/symmetricDifference.md @@ -5,11 +5,9 @@ Returns the symmetric difference between two arrays. Create a `Set` from each array, then use `Array.filter()` on each of them to only keep values not contained in the other. ```js -const symmetricDifference = (a, b) => { - const sA = new Set(a), - sB = new Set(b); - return [...a.filter(x => !sB.has(x)), ...b.filter(x => !sA.has(x))]; -}; +const symmetricDifference = (a, b) => [ + ...new Set([...a.filter(v => !b.includes(v)), ...b.filter(v => !a.includes(v))]) +]; ``` ```js