@modern-kit/utils
Version:
27 lines (23 loc) • 801 B
JavaScript
;
var validatorIsNil = require('../../validator/isNil/index.cjs');
function getRangeValues(start, end, step = 1) {
const isAscending = end >= start;
const directedStep = isAscending ? step : -step;
const length = Math.max(Math.ceil((end - start) / directedStep), 0);
const result = new Array(length);
for (let i = 0; i < result.length; i++) {
result[i] = start + directedStep * i;
}
return result;
}
function range(start, end, step = 1) {
if (validatorIsNil.isNil(end)) {
return getRangeValues(0, start);
}
if (!Number.isInteger(step) || step < 1) {
throw new Error("step\uC740 1 \uC774\uC0C1\uC758 \uC815\uC218\uC5EC\uC57C \uD569\uB2C8\uB2E4.");
}
return getRangeValues(start, end, step);
}
exports.range = range;
//# sourceMappingURL=index.cjs.map