Skip to content

Instantly share code, notes, and snippets.

@mhingston
Created December 26, 2016 22:00
Show Gist options
  • Save mhingston/2480919403a6fbe5098108e8a623ff03 to your computer and use it in GitHub Desktop.
Save mhingston/2480919403a6fbe5098108e8a623ff03 to your computer and use it in GitHub Desktop.
Python's range() for javascript
const range = (start, stop, step) =>
{
const output = [];
if(stop === undefined)
{
stop = start;
start = 0;
}
if(step === undefined)
{
step = 1;
}
for(let i=start; start < stop ? i < stop : i > stop; i += step)
{
output.push(i);
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment