Function: takeLast()
takeLast<
ElementType
>(iterable
:IterableResolvable
<ElementType
>,count
:number
):IterableIterator
<ElementType
>
Consumes the iterable and returns a new iterable with the last count
elements.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | An iterator to take values from. |
count | number | The number of values to take from the end of the iterator. |
Returns
IterableIterator
<ElementType
>
An iterator that contains the last count
elements of the provided iterator.
Example
import { takeLast } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 3, 4, 5];
console.log([...takeLast(iterable, 2)]);
// Output: [4, 5]
Remarks
This function consumes the entire iterator.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/takeLast.ts:29