Last active
September 29, 2017 18:02
-
-
Save rebolyte/60367e12d473846ebf91555ffc792c14 to your computer and use it in GitHub Desktop.
print alphabet using char codes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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