UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

27 lines (25 loc) 632 B
import { dfdlT } from "@monstermann/dfdl"; import { cloneArray, markAsMutable } from "@monstermann/remmi"; //#region src/array/drop.ts /** * `drop(array, amount)` * * Removes the first `amount` elements from `array`. * * ```ts * drop([1, 2, 3, 4, 5], 2); // [3, 4, 5] * ``` * * ```ts * pipe([1, 2, 3, 4, 5], drop(2)); // [3, 4, 5] * ``` */ const drop = dfdlT((target, amount) => { if (!Number.isInteger(amount) || target.length === 0 || amount < 0) return target; if (target.length <= amount) return markAsMutable([]); target = cloneArray(target); target.splice(0, amount); return target; }, 2); //#endregion export { drop };