2.6 KiB
2.6 KiB
id, title, challengeType, isRequired, forumTopicId
id | title | challengeType | isRequired | forumTopicId |
---|---|---|---|---|
56533eb9ac21ba0edf2244e2 | Caesars Cipher | 5 | true | 16003 |
Description
Instructions
Tests
tests:
- text: <code>rot13("SERR PBQR PNZC")</code> should decode to <code>FREE CODE CAMP</code>
testString: assert(rot13("SERR PBQR PNZC") === "FREE CODE CAMP");
- text: <code>rot13("SERR CVMMN!")</code> should decode to <code>FREE PIZZA!</code>
testString: assert(rot13("SERR CVMMN!") === "FREE PIZZA!");
- text: <code>rot13("SERR YBIR?")</code> should decode to <code>FREE LOVE?</code>
testString: assert(rot13("SERR YBIR?") === "FREE LOVE?");
- text: <code>rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")</code> should decode to <code>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</code>
testString: assert(rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.") === "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.");
Challenge Seed
function rot13(str) { // LBH QVQ VG!
return str;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Solution
var lookup = {
'A': 'N','B': 'O','C': 'P','D': 'Q',
'E': 'R','F': 'S','G': 'T','H': 'U',
'I': 'V','J': 'W','K': 'X','L': 'Y',
'M': 'Z','N': 'A','O': 'B','P': 'C',
'Q': 'D','R': 'E','S': 'F','T': 'G',
'U': 'H','V': 'I','W': 'J','X': 'K',
'Y': 'L','Z': 'M'
};
function rot13(encodedStr) {
var codeArr = encodedStr.split(""); // String to Array
var decodedArr = []; // Your Result goes here
// Only change code below this line
decodedArr = codeArr.map(function(letter) {
if(lookup.hasOwnProperty(letter)) {
letter = lookup[letter];
}
return letter;
});
// Only change code above this line
return decodedArr.join(""); // Array to String
}