|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Removes elements from the end of an array until the predicate returns false.
|
|---|
| 3 | *
|
|---|
| 4 | * This function iterates over an array from the end and drops elements until the provided
|
|---|
| 5 | * predicate function returns false. It then returns a new array with the remaining elements.
|
|---|
| 6 | *
|
|---|
| 7 | * @template T - The type of elements in the array.
|
|---|
| 8 | * @param {T[]} arr - The array from which to drop elements.
|
|---|
| 9 | * @param {(item: T, index: number, arr: T[]) => boolean} canContinueDropping - A predicate function that determines
|
|---|
| 10 | * whether to continue dropping elements. The function is called with each element from the end,
|
|---|
| 11 | * and dropping continues as long as it returns true.
|
|---|
| 12 | * @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * const array = [1, 2, 3, 4, 5];
|
|---|
| 16 | * const result = dropRightWhile(array, x => x > 3);
|
|---|
| 17 | * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
|
|---|
| 18 | */
|
|---|
| 19 | declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T, index: number, arr: readonly T[]) => boolean): T[];
|
|---|
| 20 |
|
|---|
| 21 | export { dropRightWhile };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.