Skip to content

Instantly share code, notes, and snippets.

@farskid
Created October 24, 2017 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farskid/29237f49ccd48f159a986e9ad11c02c7 to your computer and use it in GitHub Desktop.
Save farskid/29237f49ccd48f159a986e9ad11c02c7 to your computer and use it in GitHub Desktop.
Generate a range in Javascript
function recursiveRange(a, b) {
if (a + 1 === b) {
return [];
}
return [a + 1].concat(range(a + 1, b));
}
function range(a, b) {
var result = [];
for (var i = a + 1, i < b; i++) {
result.push(i);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment