Function dropLastWhile

  • Returns a new array that drops all elements in the given collection until the last element that does not match the given predicate.

    Type Parameters

    • T

      The type of the elements in the input array.

    Parameters

    • array: readonly T[]

      The array to drop elements from.

    • predicate: ((el: T) => boolean)

      The function to test each element for a condition.

        • (el): boolean
        • Parameters

          • el: T

          Returns boolean

    Returns T[]

    A new array that drops all elements until the last element that does not match the given predicate.

    import { dropLastWhile } from "@std/collections/drop-last-while";
    import { assertEquals } from "@std/assert";

    const numbers = [11, 42, 55, 20, 33, 44];

    const notFortyFour = dropLastWhile(numbers, (number) => number > 30);

    assertEquals(notFortyFour, [11, 42, 55, 20]);