Created
May 25, 2016 23:14
-
-
Save ericelliott/833fb3fb488812b8fac0bc02dff8094f to your computer and use it in GitHub Desktop.
Dream code
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
// Create a simple range from start to end, inclusive | |
const [...foo] = grange(3, 6); // [3, 4, 5, 6] | |
// Increment by 2 instead of 1 | |
const [...bar] = grange(2, 6, {step: 2}); // [2, 4, 6] | |
// Transform the output numbers with a transform function | |
const [...baz] = grange(1, 3, n => n * 2); // [2, 4, 6] | |
// Reverse the range by passing a larger value into the start position | |
const [...bif] = grange(3, 1); // [3, 2, 1] | |
// Create recurring loops | |
const loopGen = grange(1, 3, {loop: true}); | |
const loop = range(0, 7).map(() => loopGen.next().value); // [1, 2, 3, 1, 2, 3, 1, 2] | |
// Start can be omitted -- defaults to 0 | |
const [...omittedStart] = grange(6, n => n * 2, {step: 2}); // [0, 4, 8, 12] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment