Skip to content

Instantly share code, notes, and snippets.

@dormd
Created August 19, 2019 09:20
Show Gist options
  • Save dormd/246d43c52ce4a3e740e2a47048499312 to your computer and use it in GitHub Desktop.
Save dormd/246d43c52ce4a3e740e2a47048499312 to your computer and use it in GitHub Desktop.
function range(start, end, step) {
const results = [];
if (end === undefined) {
end = start;
start = 0;
}
if (step === undefined) {
step = (start < end) ? 1 : -1;
}
for (let num = start; (step > 0 && num < end) || (step < 0 && num > end); num += step) results.push(num);
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment