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

Friday, February 1, 2013

Codecademy: ROT Stands For Rotation



// 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";

// Now use it:
console.log(alphabet.rotate(13));
console.log(alphabet.rotate(13).rotate(13));

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts