Last active
March 29, 2016 10:29
-
-
Save sophiabrandt/0e03b43e68a5d5a393f0 to your computer and use it in GitHub Desktop.
Free Code Camp Basic Algorithms
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) { | |
return str.split('').map(shiftLetters).join(''); | |
function shiftLetters(letter) { | |
var charCode = letter.charCodeAt(0); | |
var shift13 = charCode + 13; | |
var over90 = 64 + (shift13 - 90); | |
return String.fromCharCode(charCode <= 64 ? charCode : shift13 > 90 ? over90: shift13); | |
} | |
} | |
// Change the inputs below to test | |
rot13("SERR PBQR PNZC"); | |
-> FREE CODE CAMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment