Skip to content

Instantly share code, notes, and snippets.

@rebolyte
Last active September 29, 2017 18:02
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 rebolyte/60367e12d473846ebf91555ffc792c14 to your computer and use it in GitHub Desktop.
Save rebolyte/60367e12d473846ebf91555ffc792c14 to your computer and use it in GitHub Desktop.
print alphabet using char codes
function range(x, y) {
if (typeof y === 'undefined') {
y = x;
x = 0;
}
let out = [];
while (x < y) {
out.push(x++);
}
return out;
}
function exclude(first, ...arrs) {
// Note that Array.prototype.includes will not do deep-equality checks on reference values
return arrs.reduce((acc, cur) => acc.filter(el => !cur.includes(el)), first);
}
// 48-57 = 0-9
// 65-90 = A-Z
// 97-122 = a-z
let alphaNumCodes = exclude(range(48, 122 + 1), range(58, 65), range(91, 96 + 1));
let alpha = alphaNumCodes.reduce((prev, cur) => prev + String.fromCharCode(cur), '');
console.log(alpha); // '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment