mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-30 18:23:22 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
739 B
739 B
takeRightWhile
Takes elements from the end of the array while the predicate function returns true
.
Signature
function takeRightWhile<T>(arr: T[], shouldContinueTaking: (item: T) => boolean): T[];
Parameters
arr
(T[]
): The array to take elements from.shouldContinueTaking
((item: T) => boolean
): The predicate function that is called with each element. Elements are included in the result as long as this function returns true.
Returns
(T[]
) A new array containing the elements taken from the end while the predicate returns true
.
Examples
// Returns [3, 2, 1]
takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
// Returns []
takeRightWhile([1, 2, 3], n => n > 3);