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

Friday, February 1, 2013

Codecademy: Write A Dictionary



// Sample solution

// Paste the rotate function here:
String.prototype.rotate = function(n) { // n is an integer
    n %= this.length; // too large numbers: modulo
    var cut = n < 0 ? -n : this.length - n; // cutting point
    return this.substr(cut) + this.substr(0,cut);
};

var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

var rot13_dict = {};
var newString = alphabet + "" + alphabet.toLowerCase();
var array1 = newString.split("");

var newString2 = alphabet.rotate(13) + "" + alphabet.rotate(13).toLowerCase();
var array2 = newString2.split("");

array1.forEach(function(element, index, array1){
rot13_dict[element]=array2[index];
});
rot13_dict;

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts