Skip to content

findAndSpliceInsert

The findAndSpliceInsert() function searches for the first element that satisfies a predicate and inserts an array of elements at that position without deleting the found element.

Interactive example

Syntax

Classic signature

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

Curried signature

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

Parameters

  • input: Original array.
  • predicate: Function determining where to insert.
  • elements: Array of elements to insert before the found element.

Return value

A new array with the inserted elements or undefined if the condition is never satisfied.

See also

Sources

Released under the MIT license.