Skip to main content

Function: dropLast()

dropLast<ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType>

Consumes the iterable, creating a new iterator without the last count elements from the iterable.

Type Parameters

Type Parameter
ElementType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>An iterator to drop values from.
countnumberThe number of values to drop from the end of the iterator.

Returns

IterableIterator<ElementType>

An iterator that contains the elements of the provided iterator, except for the last count elements.

Example

import { dropLast } from '@sapphire/iterator-utilities';

const iterable = dropLast([1, 2, 3, 4, 5], 2);
console.log([...iterable]);
// Output: [1, 2, 3]

Remarks

This function consumes the entire iterator.

Defined in

projects/utilities/packages/iterator-utilities/src/lib/dropLast.ts:28