I am getting the answers I want when I try to get character code values to print to the console from the nested array, but I am not able to reassign the character codes for some reason. I have tried nested for loops and I have tried using a while loop inside of the nested for loops, but it is not doing the reassignment so that I can return the new array and concatenate it into a string with spaces…
From what I see you are trying to reassign the character to an element of a string but in JS strings are immutable. You must create a new string with the transformed characters and replace the old one.
It is, I have the basics of the issue down, and my approach has been working up until this point. I was attempting to make the string into an array inside of a nested array and then replace the array index with the changed string from the character code…I commented out some code in the actual repl, you can see what I initially tried to do with the generate function I tried to write. It hasn’t been working, and I’ve been struggling with various iterations of the same idea since last week for this problem lol
Since it’s ROT13 try to do something different, for example, process each word in the array, calculate the ROT13 transformation for each letter in the word, build a new word from the transformed letters, and then replace the original word in the array with the new one. We can work with english letters for now and change in the future.
let array = [["SERR"], ["CVMMN"]];
let arr2 = [];
for (let i = 0; i < array.length; i++) {
for (let j = 0; j < array[i].length; j++) {
let word = array[i][j];
let newWord = "";
for (let n = 0; n < word.length; n++) {
let code = word.charCodeAt(n);
let newCode;
if (code >= 65 && code <= 90) {
// Capital letter (A-Z)
newCode = ((code - 65 + 13) % 26) + 65;
} else if (code >= 97 && code <= 122) {
// Lowercase letter (a-z)
newCode = ((code - 97 + 13) % 26) + 97;
} else {
// Other characters are left as is
newCode = code;
}
newWord += String.fromCharCode(newCode);
}
array[i][j] = newWord;
}
}
console.log(array);