Skip to content

Instantly share code, notes, and snippets.

@onurinanc
Created November 25, 2021 19:33
Show Gist options
  • Save onurinanc/0e7c9928809b32454daa9acf0b7ac05d to your computer and use it in GitHub Desktop.
Save onurinanc/0e7c9928809b32454daa9acf0b7ac05d to your computer and use it in GitHub Desktop.
function Range(start, stop, step) {
return Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
}
console.log(Range(0,5,1)) // [0, 1, 2, 3, 4, 5]
console.log(Range(0,9,3)) // [0, 3, 6, 9]
console.log(Range('A'.charCodeAt(0), 'Z'.charCodeAt(0), 1).map(x => String.fromCharCode(x)));
// ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment