From c00348686e36bd110e238091e7f47de151b29be4 Mon Sep 17 00:00:00 2001 From: Chaitanya Chandurkar Date: Sun, 22 Nov 2020 01:08:27 -0500 Subject: [PATCH 1/2] Update takeWhile.md --- snippets/takeWhile.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/takeWhile.md b/snippets/takeWhile.md index 1d66aa5ac..1574bcb6f 100644 --- a/snippets/takeWhile.md +++ b/snippets/takeWhile.md @@ -11,11 +11,11 @@ Returns the removed elements. ```js const takeWhile = (arr, func) => { - for (const [i, val] of arr.entries()) if (func(val)) return arr.slice(0, i); + for (const [i, val] of arr.entries()) if (!func(val)) return arr.slice(0, i); return arr; }; ``` ```js -takeWhile([1, 2, 3, 4], n => n >= 3); // [1, 2] +takeWhile([1, 2, 3, 4], n => n < 3); // [1, 2] ``` From e56f3461846b624aaea02bc7c68ffc0d9ba2a955 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 29 Nov 2020 11:23:01 +0200 Subject: [PATCH 2/2] Update takeWhile.md --- snippets/takeWhile.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/takeWhile.md b/snippets/takeWhile.md index 1574bcb6f..2177e2071 100644 --- a/snippets/takeWhile.md +++ b/snippets/takeWhile.md @@ -3,10 +3,10 @@ title: takeWhile tags: array,intermediate --- -Removes elements in an array until the passed function returns `true`. +Removes elements in an array until the passed function returns `false`. Returns the removed elements. -- Loop through the array, using a `for...of` loop over `Array.prototype.entries()` until the returned value from the function is `true`. +- Loop through the array, using a `for...of` loop over `Array.prototype.entries()` until the returned value from the function is `false`. - Return the removed elements, using `Array.prototype.slice()`. ```js