before hacky -> now elegant

This commit is contained in:
King
2017-12-20 22:43:33 -05:00
parent 6dc1a39bc6
commit c8bf4e197d

View File

@ -9,8 +9,10 @@ _(For a snippet that does not mutate the original array see [`without`](#without
```js ```js
const pull = (arr, ...args) => { const pull = (arr, ...args) => {
let pulled = arr.filter((v, i) => !args.toString().split(',').includes(v)); let argState = Array.isArray(args[0]) ? args[0] : args;
arr.length = 0; pulled.forEach(v => arr.push(v)); let pulled = arr.filter((v, i) => !argState.includes(v));
arr.length = 0;
pulled.forEach(v => arr.push(v));
}; };
// let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c']; // let myArray1 = ['a', 'b', 'c', 'a', 'b', 'c'];