Last active
August 29, 2015 14:11
-
-
Save nikcorg/c959f8142a270a2df4f5 to your computer and use it in GitHub Desktop.
ROT-13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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