Travis build: 568

This commit is contained in:
30secondsofcode
2018-10-01 16:35:03 +00:00
parent a950d6a565
commit 77dfa88310
3 changed files with 7 additions and 13 deletions

View File

@ -2740,15 +2740,11 @@ takeRight([1, 2, 3]); // [3]
Removes elements from the end of an array until the passed function returns `true`. Returns the removed elements.
Loop through the array, using a `for...of` loop over `Array.prototype.keys()` until the returned value from the function is `true`.
Return the removed elements, using `Array.prototype.reverse()` and `Array.prototype.slice()`.
Loop through the array, using a `Array.prototype.reduceRight()` and accumulating elements while the function returns falsy value.
```js
const takeRightWhile = (arr, func) => {
for (let i of arr.reverse().keys())
if (func(arr[i])) return arr.reverse().slice(arr.length - i, arr.length);
return arr;
};
const takeRightWhile = (arr, func) =>
arr.reduceRight((acc, el) => (func(el) ? acc : [el, ...acc]), []);
```
<details>