Hey folks! Congrats on making it through week 4 of the free JS bootcamp!
Let’s post our solutions! Here’s my initial one:
const CHARACTER_CHART = {
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) {
let decodedStr = ""
for (let i=0; i < encodedStr.length; i++) {
const char = encodedStr[i];
if (CHARACTER_CHART.hasOwnProperty(char)) {
decodedStr += CHARACTER_CHART[char];
} else {
decodedStr += char;
}
}
return decodedStr;
}
rot13("SERR PBQR PNZC");