Update symmetricDifference

No const
One time new Set()
One line code style
This commit is contained in:
浪浪浪
2018-08-10 15:47:20 +08:00
committed by GitHub
parent e99d4cef84
commit 61d3e3a29e

View File

@ -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. Create a `Set` from each array, then use `Array.filter()` on each of them to only keep values not contained in the other.
```js ```js
const symmetricDifference = (a, b) => { const symmetricDifference = (a, b) => [
const sA = new Set(a), ...new Set([...a.filter(v => !b.includes(v)), ...b.filter(v => !a.includes(v))])
sB = new Set(b); ];
return [...a.filter(x => !sB.has(x)), ...b.filter(x => !sA.has(x))];
};
``` ```
```js ```js