Skip to content

Instantly share code, notes, and snippets.

@YuCJ
YuCJ / pureSplice.js
Last active April 2, 2022 02:36
A pure version of Array.prototype.splice(). It will return a new array rather than mutate the array.
/**
* A pure version of Array.prototype.splice
* It will return a new array rather than mutate the array
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
* @param {Array} array The target array
* @param {number} start Index at which to start changing the array
* @param {number} deleteCount An integer indicating the number of old array elements to remove
* @param {any} items The elements to add to the array, beginning at the start index
* @returns {Array}
*/