Function takeLast

  • Returns a new array including the last 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, takeLast 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 lastThree = A.takeLast(3);
    lastThree([10, 20, 30, 40, 50]); // [30, 40, 50]
    lastThree([10, 20]); // []

    Type Parameters

    • T

    Parameters

    • count: number

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

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

        • arr: readonly T[]

        Returns T[]