UNPKG

@andranik-arakelyan/js-utilities

Version:
1 lines 486 B
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.range=range;exports.rangeIterable=rangeIterable;function*range(start,stop,step=1){if(stop===undefined){stop=start;start=0}if(step===0){throw new Error("Step cannot be zero")}let current=start;if(step>0){while(current<stop){yield current;current+=step}}else{while(current>stop){yield current;current+=step}}}function rangeIterable(start,stop,step=1){return{[Symbol.iterator](){return range(start,stop,step)}}}