Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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