mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-07-11 18:55:59 +09:00
Update files
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
const caesar = function (string, shift) {
|
||||
return string
|
||||
.split('')
|
||||
.map((char) => shiftChar(char, shift))
|
||||
.join('');
|
||||
return string
|
||||
.split("")
|
||||
.map((char) => shiftChar(char, shift))
|
||||
.join("");
|
||||
};
|
||||
|
||||
const codeSet = (code) => (code < 97 ? 65 : 97);
|
||||
@@ -13,14 +13,14 @@ const codeSet = (code) => (code < 97 ? 65 : 97);
|
||||
const mod = (n, m) => ((n % m) + m) % m;
|
||||
|
||||
const shiftChar = (char, shift) => {
|
||||
const code = char.charCodeAt();
|
||||
const code = char.charCodeAt();
|
||||
|
||||
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) {
|
||||
return String.fromCharCode(
|
||||
mod(code + shift - codeSet(code), 26) + codeSet(code)
|
||||
);
|
||||
}
|
||||
return char;
|
||||
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) {
|
||||
return String.fromCharCode(
|
||||
mod(code + shift - codeSet(code), 26) + codeSet(code)
|
||||
);
|
||||
}
|
||||
return char;
|
||||
};
|
||||
|
||||
module.exports = caesar;
|
||||
|
||||
Reference in New Issue
Block a user