Skip to content

Instantly share code, notes, and snippets.

@farskid
Created October 24, 2017 08:00
Show Gist options
  • 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