@arrows/array
Version:
Functional tools for JS arrays
22 lines (21 loc) • 684 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.setSize_ = void 0;
const curry_1 = require("@arrows/composition/curry");
const _setSize_ = (size, arr) => {
return size <= arr.length
? arr.slice(0, size)
: arr.slice(0).concat(new Array(size - arr.length).fill(undefined));
};
/**
* Creates a new array trimmed/extended to a provided size.
* If the new array is longer than the initial one,
* additional indexes will be set to undefined.
*
* @param size Required size
* @param arr Initial array
* @returns New array
*/
const setSize_ = curry_1.default(_setSize_);
exports.setSize_ = setSize_;
exports.default = setSize_;
;