Travis build: 2071

This commit is contained in:
30secondsofcode
2018-05-17 14:29:22 +00:00
parent 0203302ae1
commit 90e8fec04d
2 changed files with 4 additions and 4 deletions

View File

@ -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;
};
```