Skip to content

Instantly share code, notes, and snippets.

@tannerdolby
Last active January 12, 2023 04:35
Show Gist options
  • Save tannerdolby/eabb2f99c166469d4d9de19afaa862ac to your computer and use it in GitHub Desktop.
Save tannerdolby/eabb2f99c166469d4d9de19afaa862ac to your computer and use it in GitHub Desktop.
Alphabet class containing the english alphabet in both upper and lower casing.
class Alphabet {
constructor() {
this.lowercaseStr = '';
this.uppercaseStr = '';
this.lowercaseArr = [];
this.uppercaseArr = [];
this.letters = this.getAlphabet();
this._init();
}
_init() {
for (const letter in this.letters) {
if (letter === letter.toUpperCase()) {
this.uppercaseStr += letter;
this.uppercaseArr.push(letter);
} else {
this.lowercaseStr += letter;
this.lowercaseArr.push(letter);
}
}
}
_setLetters(start, end, arr) {
for (let i=start; i < end; i++) {
arr[String.fromCharCode(i)] = i;
}
}
getAlphabet() {
const alphabet = [];
this._setLetters(65, 91, alphabet);
this._setLetters(97, 123, alphabet);
return alphabet;
}
}
const alphabet = new Alphabet();
console.log(alphabet);
/*
Alphabet {
lowercaseStr: 'abcdefghijklmnopqrstuvwxyz',
uppercaseStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
lowercaseArr:
[ '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' ],
uppercaseArr:
[ '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' ],
letters:
[ A: 65,
B: 66,
C: 67,
D: 68,
E: 69,
F: 70,
G: 71,
H: 72,
I: 73,
J: 74,
K: 75,
L: 76,
M: 77,
N: 78,
O: 79,
P: 80,
Q: 81,
R: 82,
S: 83,
T: 84,
U: 85,
V: 86,
W: 87,
X: 88,
Y: 89,
Z: 90,
a: 97,
b: 98,
c: 99,
d: 100,
e: 101,
f: 102,
g: 103,
h: 104,
i: 105,
j: 106,
k: 107,
l: 108,
m: 109,
n: 110,
o: 111,
p: 112,
q: 113,
r: 114,
s: 115,
t: 116,
u: 117,
v: 118,
w: 119,
x: 120,
y: 121,
z: 122 ] }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment