UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

21 lines (20 loc) 778 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.arraySpliceMultiple = void 0; /** * Splices multiple segments at once with a single call. * @author @dailker * @template T * @param {T[]} array - The array to splice. * @param {Array<{start: number, deleteCount: number, items?: T[]}>} splices - Array of splice instructions. * @returns {T[]} The modified array. */ function arraySpliceMultiple(array, splices) { // Sort splices in reverse order to avoid index shifting splices.sort((a, b) => b.start - a.start); for (const { start, deleteCount, items } of splices) { array.splice(start, deleteCount, ...(items || [])); } return array; } exports.arraySpliceMultiple = arraySpliceMultiple;