Last active
March 26, 2019 21:44
-
-
Save andrevinsky/76f14446107e842f26753646750c5196 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
const range = function* ( | |
from, | |
to, | |
step = from > to ? -1 : 1 | |
) { | |
if ( | |
step < 0 | |
? from <= to | |
: from >= to | |
) { | |
return; | |
} | |
yield from; | |
return yield* range(from + step, to, step); | |
}; |
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
const range = (start, stop, step = 1) => | |
Array(Math.ceil((stop - start) / step)) | |
.fill(start) | |
.map((x, y) => x + y * step); | |
//Which i'm using with: | |
for (y of range(minY, maxY)) { | |
//foo | |
} |
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(from, to, step=1) { | |
const sign = Math.sign(step) | |
for (let i = 0; (from + i * step) * sign < to * step; i++) { | |
yield from + i * step | |
} | |
} | |
Array.from(range(5, 1, -1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment