es-toolkit/docs/reference/array/takeRightWhile.md
Minsoo Kim cf65b2c601
style(*): Setup prettier and apply formatting (#24)
* chore: add prettierrc

* chore: apply format with prettier config

* chore: eslint error fix
2024-06-04 17:19:26 +09:00

29 lines
739 B
Markdown

# takeRightWhile
Takes elements from the end of the array while the predicate function returns `true`.
## Signature
```typescript
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
```typescript
// Returns [3, 2, 1]
takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
// Returns []
takeRightWhile([1, 2, 3], n => n > 3);
```