Skip to content

Instantly share code, notes, and snippets.

@patrickroberts
Last active September 18, 2017 22:34
Show Gist options
  • Save patrickroberts/51244bc23c77ccf3cb5ebddd23d197b1 to your computer and use it in GitHub Desktop.
Save patrickroberts/51244bc23c77ccf3cb5ebddd23d197b1 to your computer and use it in GitHub Desktop.
standard test fail (possible bug)
function characterRange (minCharacter, maxCharacter) {
const lower = minCharacter.charCodeAt(0)
const upper = maxCharacter.charCodeAt(0)
return Array(upper - lower + 1)
.fill()
.map((_, index) => String.fromCharCode(lower + index))
.join('')
}
const base64 =
characterRange('A', 'Z') +
characterRange('a', 'z') +
characterRange('0', '9') +
'+/'
const unbase64 = Array.from(base64)
.reduce((table, character, index) => {
table[character.charCodeAt(0)] = index
return table
}), { ['='.charCodeAt(0)]: 64 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment