Skip to content

Instantly share code, notes, and snippets.

@qubyte
Last active October 6, 2015 15:07
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 qubyte/91309d5a96917bd6696e to your computer and use it in GitHub Desktop.
Save qubyte/91309d5a96917bd6696e to your computer and use it in GitHub Desktop.
Simple python-like range function for ES2015. Requires at least start and stop parameters, and takes an optional step parameter.
function* range(start, stop, step = 1) {
for (let n = start; n < stop; n += step) {
yield n;
}
}
@qubyte
Copy link
Author

qubyte commented Oct 6, 2015

You can use this to do such things as:

for (const i of range(0, 10)) {
  // stuff using i
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment