UNPKG

@arrows/array

Version:
26 lines (25 loc) 781 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.insert_ = void 0; const curry_1 = require("@arrows/composition/curry"); const _insert_ = (value, index, arr) => { return index >= arr.length ? arr.concat([value]) : arr .slice(0, index) .concat([value]) .concat(arr.slice(index)); }; /** * Creates a new array with an additional value at the provided index. * Shifts old values to the right. * If the index is out of bound of the array - adds a value as a last element. * * @param value Additional value * @param index Specific index * @param arr Initial array * @returns New array */ const insert_ = curry_1.default(_insert_); exports.insert_ = insert_; exports.default = insert_;