Created
September 5, 2018 00:57
-
-
Save stevenYouhana/6b979e2cecb6c0e04979ad1bc2f38afe to your computer and use it in GitHub Desktop.
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 rot13(str) { // LBH QVQ VG! | |
const A_Z = ['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']; | |
function repLetter(L) { | |
if(L > 'M') { | |
return A_Z[(A_Z.indexOf(L)-13)]; | |
} | |
else return A_Z[(A_Z.indexOf(L)+13)]; | |
} | |
return str.split('').map(e => { | |
return /[A-Z]/.test(e)? repLetter(e): | |
e; | |
}).join(''); | |
} | |
// Change the inputs below to test | |
rot13("SERR PBQR PNZC"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment