Skip to content

Instantly share code, notes, and snippets.

@nikcorg
Last active August 29, 2015 14:11
Show Gist options
  • Save nikcorg/c959f8142a270a2df4f5 to your computer and use it in GitHub Desktop.
Save nikcorg/c959f8142a270a2df4f5 to your computer and use it in GitHub Desktop.
ROT-13
String.prototype.map = function (fn) {
var input = this;
function step(acc, i, idx) {
return acc + fn(i, idx, input);
}
return Array.prototype.reduce.call(this, step, "");
};
function rot13(c) {
var read = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var write = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
var p = read.indexOf(c);
if (p > -1) {
return write.charAt(p);
}
return c;
}
console.log("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis elementum sagittis ultricies. Aenean convallis semper tortor. Sed nunc risus, pellentesque id ultricies ac, consequat et sem.".map(rot13));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment