@mirei/ts-collections
    Preparing search index...

    Function takeLast

    • Returns up to the specified number of trailing elements from source.

      Type Parameters

      • TElement

        Type of elements within source.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • count: number

        Number of elements to keep from the end; values less than or equal to zero produce an empty sequence.

      Returns IEnumerable<TElement>

      A deferred sequence containing at most count elements from the end of source.

      The implementation buffers up to count elements to determine the tail, so memory usage grows with count. The source must be finite.

      const numbers = [1, 2, 3, 4, 5];
      const lastTwo = takeLast(numbers, 2).toArray();
      console.log(lastTwo); // [4, 5]

      const emptyTakeLast = takeLast(numbers, 0).toArray();
      console.log(emptyTakeLast); // []