1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 14:16:55 +02:00
CodeWars/5kyu/rot13/solution.js
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

17 lines
394 B
JavaScript

function rot13(message) {
let result = "";
for (let character of message) {
let val = character.charCodeAt();
if (val >= 97 && val <= 122) {
result += String.fromCharCode(97 + (val - 97 + 13) % 26);
} else if (val >= 65 && val <= 90) {
result += String.fromCharCode(65 + (val - 65 + 13) % 26);
} else {
result += character;
}
}
return result;
}