takeLastWhile
import { takeLastWhile } from "jsr:@ende/collections";function
function takeLastWhile<T>(iterable: Iterable<T>, predicate: (el: T, index: number) => boolean): T[]Returns all elements in the given iterable after the last element that does not match the given predicate.
iterable: Iterable<T>The iterable to take elements from.
predicate: (el: T, index: number) => booleanThe predicate function to determine if an element should be included. The function receives the element and its index.
Returns
An array containing all elements after the last element that does not match the predicate.
Example: Basic usage
import { takeLastWhile } from "@ende/collections/take-last-while";
import { assertEquals } from "@ende/assert";
const numbers = [1, 2, 3, 4, 5, 6];
const result = takeLastWhile(numbers, (number) => number > 4);
assertEquals(result, [5, 6]);
Example: Using the index parameter
import { takeLastWhile } from "@ende/collections/take-last-while";
import { assertEquals } from "@ende/assert";
const array = [20, 30, 20];
const result = takeLastWhile(array, (_, index) => index > 0);
assertEquals(result, [30, 20]);