diff --git a/caesar/caesar.js b/caesar/caesar.js index c2e926f..b6dcd95 100644 --- a/caesar/caesar.js +++ b/caesar/caesar.js @@ -1,7 +1,7 @@ -const caesar = function(string, shift) { +const caesar = function(string, shiftValue) { return string .split("") - .map(char => shiftChar(char, shift)) + .map(char => shift(char, shiftValue)) .join(""); }; @@ -12,12 +12,12 @@ const codeSet = code => (code < 97 ? 65 : 97); // https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers const mod = (n, m) => (n % m + m) % m; -const shiftChar = (char, shift) => { +const shift = (char, shiftValue) => { const code = char.charCodeAt(); if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) { return String.fromCharCode( - mod(code + shift - codeSet(code), 26) + codeSet(code) + mod(code + shiftValue - codeSet(code), 26) + codeSet(code) ); } return char;