Skip to content

Commit

Permalink
Merge pull request Chalarangelo#244 from kingdavidmartins/pullAll
Browse files Browse the repository at this point in the history
add pullAll
  • Loading branch information
Chalarangelo authored Dec 19, 2017
2 parents f556a3a + 6c9a522 commit b992c7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions snippets/pullAll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### pullAll

Mutates the original array to filter out the values specified (accepts an array of values).

Use `Array.filter()` and `Array.includes()` to pull out the values that are not needed.
Use `Array.length = 0` to mutate the passed in array by resetting it's length to zero and `Array.push()` to re-populate it with only the pulled values.

```js
const pullAll = (arr, pullArr) => {
let pulled = arr.filter((v, i) => !pullArr.includes(v));
arr.length = 0; pulled.forEach(v => arr.push(v));
}
// let myArray = ['a', 'b', 'c', 'a', 'b', 'c'];
// pullAll(myArray, ['a', 'c']);
// console.log(myArray) -> [ 'b', 'b' ]
```
1 change: 1 addition & 0 deletions tag_database
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pipe:function
powerset:math
promisify:function
pull:array
pullAll:array
randomIntegerInRange:math
randomNumberInRange:math
readFileLines:node
Expand Down

0 comments on commit b992c7d

Please sign in to comment.