Skip to content

Instantly share code, notes, and snippets.

@stevenYouhana
Created September 5, 2018 00:57
Show Gist options
  • Save stevenYouhana/6b979e2cecb6c0e04979ad1bc2f38afe to your computer and use it in GitHub Desktop.
Save stevenYouhana/6b979e2cecb6c0e04979ad1bc2f38afe to your computer and use it in GitHub Desktop.
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