Caesar's Cipher Feedback/Refactoring advice

Caesar's Cipher Feedback/Refactoring advice
0

#1

Hey all, I’ve just wrapped up Caesar’s Cipher, looking for some ways to improve…

`function rot13(str) {
  strArr = [];
  for (var i =0, len = str.length; i < len; i++) {
   var charCode = str.charCodeAt(i);
   // Check if the charCode is A-M (65-77)
  if (charCode >= 65 && charCode <= 77) {
  // Add 13 from each of the charCodes
    strArr.push(charCode + 13);
  } else if (charCode >=78 && charCode <= 90){
    strArr.push(charCode - 13);
  } else {
    strArr.push(charCode);
 }
}
newArr =[];
for (var i=0, len=strArr.length; i < len; i++) {
  newArr.push(String.fromCharCode(strArr[i]));
}
// return the new string
return newArr.join('');
}`

Thanks!


#3

Thank you for the feedback, it’s appreciated! :burrito: