Created
October 24, 2017 08:00
-
-
Save farskid/29237f49ccd48f159a986e9ad11c02c7 to your computer and use it in GitHub Desktop.
Generate a range in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recursiveRange(a, b) { | |
if (a + 1 === b) { | |
return []; | |
} | |
return [a + 1].concat(range(a + 1, b)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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