Merge pull request #960 from henrycjchen/master

update-dropRightWhilejust: slice arr once
This commit is contained in:
Angelos Chalaris
2019-05-29 09:16:18 +03:00
committed by GitHub

View File

@ -7,8 +7,9 @@ Returns the remaining elements.
```js
const dropRightWhile = (arr, func) => {
while (arr.length > 0 && !func(arr[arr.length - 1])) arr = arr.slice(0, -1);
return arr;
let rightIndex = arr.length;
while (rightIndex-- && !func(arr[rightIndex]));
return arr.slice(0, rightIndex + 1);
};
```