Function dropWhile

  • Returns a new array that drops all elements in the given collection until the first 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 first element that does not match the given predicate.

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

    const numbers = [3, 2, 5, 2, 5];
    const dropWhileNumbers = dropWhile(numbers, (number) => number !== 2);

    assertEquals(dropWhileNumbers, [2, 5, 2, 5]);