UNPKG

566 BJavaScriptView Raw
1import { _isArray } from './_internals/_isArray'
2
3export function takeLastWhile(predicate, input){
4 if (arguments.length === 1){
5 return _input => takeLastWhile(predicate, _input)
6 }
7 if (input.length === 0) return input
8 let found = false
9 const toReturn = []
10 let counter = input.length
11
12 while (!found || counter === 0){
13 counter--
14 if (predicate(input[ counter ]) === false){
15 found = true
16 } else if (!found){
17 toReturn.push(input[ counter ])
18 }
19 }
20
21 return _isArray(input) ? toReturn.reverse() : toReturn.reverse().join('')
22}