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