Skip to content

findAndSpliceDelete

The findAndSpliceDelete() function searches for the first element that satisfies a predicate, then deletes deleteCount elements starting from that index.

Interactive example

Syntax

Classic signature

typescript
function findAndSpliceDelete<
	GenericElement extends unknown
>(
	input: readonly GenericElement[],
	predicate: (
		element: GenericElement,
		params: { index: number }
	) => boolean,
	deleteCount: number
): GenericElement[] | undefined

Curried signature

typescript
function findAndSpliceDelete<
	GenericElement extends unknown
>(
	predicate: (
		element: GenericElement,
		params: { index: number }
	) => boolean,
	deleteCount: number
): (input: readonly GenericElement[]) => GenericElement[] | undefined

Parameters

  • input: Array to traverse.
  • predicate: Function that identifies the element to delete. Receives the element and its index.
  • deleteCount: Number of elements to remove starting from the found element.

Return value

A new array with the elements removed or undefined if no element satisfies the predicate.

See also

Sources

Released under the MIT license.