@modern-kit/utils
Version:
25 lines (22 loc) • 758 B
JavaScript
import { isNil } from '../../validator/isNil/index.mjs';
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 (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);
}
export { range };
//# sourceMappingURL=index.mjs.map