Function take

  • Returns a new array including the first count elements. Returns an empty array if count is not an integer or is negative. To prevent unexpected behavior from returning a non-empty but shorter than expected array, take also returns an empty array if count exceeds the length of the array. To return the entire array instead in this case, use slice.

    Example

    import * as A from "flurp/array";

    const firstThree = A.take(3);
    firstThree([10, 20, 30, 40, 50]); // [10, 20, 30]
    firstThree([10, 20]); // []

    Type Parameters

    • T

    Parameters

    • count: number

    Returns ((arr: readonly T[]) => T[])

      • (arr: readonly T[]): T[]
      • Parameters

        • arr: readonly T[]

        Returns T[]