dropLastWhile
import { dropLastWhile } from "jsr:@ende/collections";function
function dropLastWhile<T>(iterable: Iterable<T>, predicate: (el: T, index: number) => boolean): T[]Returns an array that drops all elements in the given iterable until the last element that does not match the given predicate.
iterable: Iterable<T>The iterable to drop elements from.
predicate: (el: T, index: number) => booleanThe function to test each element for a condition. The function receives the element and its index.
Returns
An array that drops all elements until the last element that does not match the given predicate.
Example: Basic usage
import { dropLastWhile } from "@ende/collections/drop-last-while";
import { assertEquals } from "@ende/assert";
const numbers = [11, 42, 55, 20, 33, 44];
const notFortyFour = dropLastWhile(numbers, (number) => number > 30);
assertEquals(notFortyFour, [11, 42, 55, 20]);
Example: Using the index parameter
import { dropLastWhile } from "@ende/collections/drop-last-while";
import { assertEquals } from "@ende/assert";
const array = [20, 30, 20];
const result = dropLastWhile(array, (_, index) => index > 1);
assertEquals(result, [20, 30]);