findAndSpliceReplace
The findAndSpliceReplace() function looks for an element with a predicate and replaces it, along with the following elements, with an array of new values.
Interactive example
Syntax
Classic signature
typescript
function findAndSpliceReplace<
GenericElement extends unknown
>(
input: readonly GenericElement[],
predicate: (
element: GenericElement,
params: { index: number }
) => boolean,
elements: GenericElement[]
): GenericElement[] | undefinedCurried signature
typescript
function findAndSpliceReplace<
GenericElement extends unknown
>(
predicate: (
element: GenericElement,
params: { index: number }
) => boolean,
elements: GenericElement[]
): (input: readonly GenericElement[]) => GenericElement[] | undefinedParameters
input: Array to modify.predicate: Condition for finding the position to replace.elements: Values that will replace those present from the found index onward. Their count determines how many elements are overwritten.
Return value
A new array with the replacements, or undefined if no element is found.
