RosettaCodeData/Task/Rot-13/JavaScript/rot-13-1.js

7 lines
240 B
JavaScript

function rot13(c) {
return c.replace(/([a-m])|([n-z])/ig, function($0,$1,$2) {
return String.fromCharCode($1 ? $1.charCodeAt(0) + 13 : $2 ? $2.charCodeAt(0) - 13 : 0) || $0;
});
}
rot13("ABJURER nowhere") // NOWHERE abjurer