From 21c7e06f7fe87872e47d9cd524da220b2977da56 Mon Sep 17 00:00:00 2001 From: King Date: Mon, 18 Dec 2017 14:32:05 -0500 Subject: [PATCH 1/3] add pullAll --- snippets/pullAll.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 snippets/pullAll.md diff --git a/snippets/pullAll.md b/snippets/pullAll.md new file mode 100644 index 000000000..d630aab99 --- /dev/null +++ b/snippets/pullAll.md @@ -0,0 +1,18 @@ +### 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. + +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' ] +``` \ No newline at end of file From 1053a662831c40316eb0b87ab65c64f88c6dc0c7 Mon Sep 17 00:00:00 2001 From: King Date: Mon, 18 Dec 2017 14:40:26 -0500 Subject: [PATCH 2/3] ran npm tagger & updated pullAll:array -> tag_database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index f48f069b3..d1f687a4b 100644 --- a/tag_database +++ b/tag_database @@ -71,6 +71,7 @@ pipe:function powerset:math promisify:function pull:array +pullAll:array randomIntegerInRange:math randomNumberInRange:math readFileLines:node From 69552ca086c34d55df5c895ce7ab4160b3acae16 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Dec 2017 12:59:39 +0200 Subject: [PATCH 3/3] 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 +```