I am pretty much solved this algorithm challenge, but I do not know how to use regex to add in the spaces.
Here is my code
/*
requirment: if input is a letter => shift 13 places then output the result
if input is a space, output space
*/
function rot(str) {
const ALPHABET = ["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"];
var input_num = 0;
var output_num = 0;
var output = "";
//outer loop for str
for (let i = 0; i < str.length; i++) {
//inner loop for ALPHABET
for (let j = 0; j < ALPHABET.length; j++) {
if (ALPHABET[j] === str[i]) {
input_num = j;
output_num = input_num + 13;
if (output_num > 25) {
output_num = output_num - 26;
}
output = output + ALPHABET[output_num];
}
}
}
console.log(output);
}
rot("SERR PBQR PNZC");