Inline codeSet and use const variable instead
1) codeSet is not a good function name, since it includes no verb 2) extracting a const variable makes the function call redudant and shortens line 24 to be less than 80 characters wide
This commit is contained in:
parent
b4909d27a3
commit
7beb49e593
|
@ -5,8 +5,6 @@ const caesar = function(string, shiftValue) {
|
||||||
.join("");
|
.join("");
|
||||||
};
|
};
|
||||||
|
|
||||||
const codeSet = code => (code < 97 ? 65 : 97);
|
|
||||||
|
|
||||||
// This function implements a version of the modulo operator
|
// This function implements a version of the modulo operator
|
||||||
// that returns the smallest positive remainder even for negative inputs.
|
// that returns the smallest positive remainder even for negative inputs.
|
||||||
// See this link for details:
|
// See this link for details:
|
||||||
|
@ -17,7 +15,8 @@ const shift = (char, shiftValue) => {
|
||||||
const code = char.charCodeAt();
|
const code = char.charCodeAt();
|
||||||
|
|
||||||
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) {
|
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) {
|
||||||
const shiftedCode = mod(code + shiftValue - codeSet(code), 26) + codeSet(code);
|
const base = code < 97 ? 65 : 97;
|
||||||
|
const shiftedCode = mod(code + shiftValue - base, 26) + base;
|
||||||
return String.fromCharCode(shiftedCode);
|
return String.fromCharCode(shiftedCode);
|
||||||
}
|
}
|
||||||
return char;
|
return char;
|
||||||
|
|
Loading…
Reference in New Issue