From 6c9a5226aaef8c8c2ed9b2ca52b85fdbfe7ca9ff Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Dec 2017 12:59:39 +0200 Subject: [PATCH] Update pullAll.md --- snippets/pullAll.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/snippets/pullAll.md b/snippets/pullAll.md index d630aab99..ab8bf2285 100644 --- a/snippets/pullAll.md +++ b/snippets/pullAll.md @@ -1,6 +1,6 @@ ### pullAll -This method is like pull except that it accepts an array of values to filter out before Mutating and pulling all the values from the original array. +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. @@ -8,11 +8,9 @@ Use `Array.length = 0` to mutate the passed in array by resetting it's length to ```js const pullAll = (arr, pullArr) => { let pulled = arr.filter((v, i) => !pullArr.includes(v)); - arr.length = 0; - pulled.forEach(v => arr.push(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' ] -``` \ No newline at end of file +```