Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, May 13, 2017

FreeCodeCamp Caesars Cipher Sample Solution


function rot13(str) {
  var num = [];
  for(var i=0; i<str.length; i++){
    num.push(str.charCodeAt(i));
  }
 
  var num2 = num.map( function(value) {
    //A to Z is between 65 and 90 so only convert these values
    if(value>=65 && value<=90){
      if(value-13 >= 65){
        return value - 13;
      } else {
        return value + 13;
      }
    } else {
      return value;
    }
  });
 
  var num3 = [];
  for(var j=0; j<num2.length; j++){
    num3.push(String.fromCharCode(num2[j]));
  }
 
  return num3.join('');
}

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts