Last active
November 26, 2016 10:04
-
-
Save MiracleBlue/c6a9800700a47f7a14e4805f13461246 to your computer and use it in GitHub Desktop.
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
// So this is fking incredible. Its actually possible to | |
// do totally immutable state inside a generator. | |
// No mutations. No 'let's. No shame! | |
function* range(start, end, step = 1, current = start) { | |
yield current; | |
if (current < end) yield* range(start, end, step, current + step); | |
} | |
// In the name of the Turing, and of the Crockford, and of the holy Atwood, Amen. | |
console.log(...range(5, 15)); | |
// => 5 6 7 8 9 10 11 12 13 14 15 | |
console.log(...range(5, 15, 2)); | |
// => 5 7 9 11 13 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment