Refactor takeRightWhile

This commit is contained in:
Siarhei
2018-09-20 18:10:31 +04:00
parent bc0b19122f
commit 9c6087c4ac
2 changed files with 3 additions and 12 deletions

View File

@ -1,6 +1,2 @@
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], []);
module.exports = takeRightWhile;