Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created May 25, 2011 12:30
Show Gist options
  • Select an option

  • Save xulapp/990865 to your computer and use it in GitHub Desktop.

Select an option

Save xulapp/990865 to your computer and use it in GitHub Desktop.
function range(start, end, step) {
if (arguments.length < 1)
throw new TypeError('range expected at least 1 arguments, got 0');
if (arguments.length < 2)
end = start, start = 0;
if (arguments.length < 3)
step = 1;
start |= 0, end |= 0, step |= 0;
if (!step)
throw new Error('range() step argument must not be zero');
if (step < 0)
for (var i = start; end < i; i += step)
yield i;
else
for (var i = start; i < end; i += step)
yield i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment