Skip to content

Instantly share code, notes, and snippets.

@intrnl
Created May 26, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intrnl/11d346b0715154b36a946fc155e2f897 to your computer and use it in GitHub Desktop.
Save intrnl/11d346b0715154b36a946fc155e2f897 to your computer and use it in GitHub Desktop.
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);
}
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