UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

27 lines (25 loc) 620 B
import { dfdlT } from "@monstermann/dfdl"; import { cloneArray } from "@monstermann/remmi"; //#region src/array/remove.ts /** * `remove(target, value)` * * Removes the first occurrence of `value` from `target` array. If the value is not found, returns the original array unchanged. * * ```ts * remove([1, 2, 3, 2], 2); // [1, 3, 2] * ``` * * ```ts * pipe([1, 2, 3, 2], remove(2)); // [1, 3, 2] * ``` */ const remove = dfdlT((target, value) => { const idx = target.indexOf(value); if (idx < 0) return target; target = cloneArray(target); target.splice(idx, 1); return target; }, 2); //#endregion export { remove };