Created
May 26, 2020 15:05
-
-
Save intrnl/11d346b0715154b36a946fc155e2f897 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
function range (from, to) { | |
if (!to) { | |
to = from; | |
from = 0; | |
} | |
if (from > to) { | |
throw RangeError('`from` is higher than `to`'); | |
} | |
return Array.from({ length: to - from }, (_, i) => i + from); | |
} |
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) { | |
if (!to) { | |
to = from; | |
from = 0; | |
} | |
if (from > to) { | |
throw RangeError('`from` is higher than `to`'); | |
} | |
for (let i = from; i < to; i++) { | |
yield i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment