Skip to content

Instantly share code, notes, and snippets.

@wehrhaus
Created June 12, 2018 17:19
Show Gist options
  • Save wehrhaus/d1a0f91606724ab68419b20d53520fe7 to your computer and use it in GitHub Desktop.
Save wehrhaus/d1a0f91606724ab68419b20d53520fe7 to your computer and use it in GitHub Desktop.
Create a range of numbers
function* range(start, end) {
yield start;
if (start === end) return;
yield* range(start + 1, end);
}
const createRange = (a, b) => [...range(a, b)];
// Example Usage: Create array of lowercase alphabet
const alphabet = createRange(97, 122).map(k => String.fromCharCode(k));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment