@arrows/array
Version:
Functional tools for JS arrays
26 lines (25 loc) • 716 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.set_ = void 0;
const curry_1 = require("@arrows/composition/curry");
const _set_ = (value, index, arr) => {
if (index > arr.length - 1) {
throw new Error("The provided index is out of bound of the array.");
}
const newArr = [...arr];
newArr[index] = value;
return newArr;
};
/**
* Creates a new array with a new value at the provided index.
*
* If the index is out of bound of the array throws an error.
*
* @param value New value
* @param index Specific index
* @param arr Initial array
* @returns New array
*/
const set_ = curry_1.default(_set_);
exports.set_ = set_;
exports.default = set_;
;