Skip to content

Instantly share code, notes, and snippets.

@Sparkenstein
Created February 25, 2019 09:59
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 Sparkenstein/f5b3f4c06484be58ba08bce90fb1b536 to your computer and use it in GitHub Desktop.
Save Sparkenstein/f5b3f4c06484be58ba08bce90fb1b536 to your computer and use it in GitHub Desktop.
python like range genrator function in js
const range = function* (from, to, step = 1) {
let i = from;
if (from < to) {
while (i + step <= to) {
yield i = i + step;
}
} else {
while (i >= to + step) {
yield i = i - step;
}
}
}
const r = [...range(20, 10, 02)]
console.log(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment