From 4110110a1b7d068b186a4998dd95547cf1fc592b Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 19 Dec 2017 13:24:57 +0200 Subject: [PATCH] Update pullAtIndex.md --- snippets/pullAtIndex.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/pullAtIndex.md b/snippets/pullAtIndex.md index e9efc172d..0e0d8cf7f 100644 --- a/snippets/pullAtIndex.md +++ b/snippets/pullAtIndex.md @@ -1,6 +1,6 @@ ### pullAtIndex -This method is like pull except that it accepts an array of indexes to filter out before Mutating and pulling all the values from the original array. Which then returns an array of removed elements. +Mutates the original array to filter out the values at the specified indexes. 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. @@ -11,7 +11,7 @@ const pullAtIndex = (arr, pullArr) => { let removed = []; let pulled = arr.map((v, i) => pullArr.includes(i) ? removed.push(v) : v) .filter((v, i) => !pullArr.includes(i)) - arr.length = 0; + arr.length = 0; pulled.forEach(v => arr.push(v)); return removed; } @@ -21,4 +21,4 @@ const pullAtIndex = (arr, pullArr) => { // console.log(myArray); -> [ 'a', 'c' ] // console.log(pulled); -> [ 'b', 'd' ] -``` \ No newline at end of file +```