Skip to content

Instantly share code, notes, and snippets.

@sakilk130
Last active May 30, 2021 14:29
Show Gist options
  • Save sakilk130/74d93f8b0f76dbeba82ef83b4d7dfc68 to your computer and use it in GitHub Desktop.
Save sakilk130/74d93f8b0f76dbeba82ef83b4d7dfc68 to your computer and use it in GitHub Desktop.
FreeCodeCamp JavaScript Project
function rot13(str) {
const Acode = 'A'.charCodeAt();
const Ncode = 'N'.charCodeAt();
const Zcode = 'Z'.charCodeAt();
return [...str]
.map(function (e) {
const code = e.charCodeAt();
if (Acode <= code && code <= Zcode) {
if (code < Ncode) {
return String.fromCharCode(code + 13);
} else {
return String.fromCharCode(code - 13);
}
} else {
return e;
}
})
.join('');
}
rot13('SERR PBQR PNZC');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment