Skip to content

Instantly share code, notes, and snippets.

@tannerdolby
Last active January 13, 2023 04:17
Show Gist options
  • Save tannerdolby/be2535e09af87cb3e345b3b71d763f10 to your computer and use it in GitHub Desktop.
Save tannerdolby/be2535e09af87cb3e345b3b71d763f10 to your computer and use it in GitHub Desktop.
function getAlphabet(lowercase) {
const alphabet = [];
const start = lowercase ? 65 : 97;
const end = lowercase ? 91 : 123;
for (let i=start, j=0; i < end; i++, j++) {
alphabet[j] = String.fromCharCode(i);
}
return alphabet;
}
const l = getAlphabet();
const u = getAlphabet(true);
console.log(l[0], l[25]);
console.log(u[0], u[25]);
console.log(l);
console.log(u);
/*
a z
A Z
[ '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' ]
[ '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