From 7afdc10372c1627e5a8d77a0cfd3aa547d221f78 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 17 May 2018 14:29:22 +0000 Subject: [PATCH] Travis build: 2071 --- README.md | 4 ++-- docs/array.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26117608c..387924411 100644 --- a/README.md +++ b/README.md @@ -2670,12 +2670,12 @@ takeRightWhile([1, 2, 3, 4], n => n < 3); // [3, 4] Removes elements in an array until the passed function returns `true`. Returns the removed elements. -Loop through the array, using a `for...of` loop over `Array.keys()` until the returned value from the function is `true`. +Loop through the array, using a `for...of` loop over `Array.entries()` until the returned value from the function is `true`. Return the removed elements, using `Array.slice()`. ```js const takeWhile = (arr, func) => { - for (let i of arr.keys()) if (func(arr[i])) return arr.slice(0, i); + for (const [i, val] of arr.entries()) if (func(val)) return arr.slice(0, i); return arr; }; ``` diff --git a/docs/array.html b/docs/array.html index 7b411c070..60e8e5f70 100644 --- a/docs/array.html +++ b/docs/array.html @@ -469,8 +469,8 @@ return arr; };
takeRightWhile([1, 2, 3, 4], n => n < 3); // [3, 4]
-

takeWhile

Removes elements in an array until the passed function returns true. Returns the removed elements.

Loop through the array, using a for...of loop over Array.keys() until the returned value from the function is true. Return the removed elements, using Array.slice().

const takeWhile = (arr, func) => {
-  for (let i of arr.keys()) if (func(arr[i])) return arr.slice(0, i);
+

takeWhile

Removes elements in an array until the passed function returns true. Returns the removed elements.

Loop through the array, using a for...of loop over Array.entries() until the returned value from the function is true. Return the removed elements, using Array.slice().

const takeWhile = (arr, func) => {
+  for (const [i, val] of arr.entries()) if (func(val)) return arr.slice(0, i);
   return arr;
 };
 
takeWhile([1, 2, 3, 4], n => n >= 3); // [1, 2]