Created
June 9, 2019 13:27
-
-
Save imedadel/10f6ddbce474f6a8adae489e19ad2447 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const bigN = 13 | |
const alphas = 26 | |
const lowerCaseA = 'a'.charCodeAt(0) | |
const upperCaseA = 'A'.charCodeAt(0) | |
const rotate = str => str | |
.normalize('NFD') | |
.split('') | |
.map(chr => chr.charCodeAt(0)) | |
.map(charCode => | |
(lowerCaseA <= charCode && charCode < lowerCaseA + alphas) ? ((charCode - lowerCaseA + bigN) % alphas) + lowerCaseA : | |
(upperCaseA <= charCode && charCode < upperCaseA + alphas) ? ((charCode - upperCaseA + bigN) % alphas) + upperCaseA : | |
charCode | |
) | |
.map(charCode => String.fromCharCode(charCode)) | |
.join('') | |
const onChange = () => { | |
const input = document.querySelector('.rot13__input') | |
const output = document.querySelector('.rot13__output') | |
output.value = rotate(input.value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment