Skip to content

Commit c9e3da8

Browse files
committed
let replaced by const
1 parent e300b88 commit c9e3da8

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

challenges/easy/caesar-cipher/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
function encode(word: string, shift: number) {
22

33
shift = shift % 26;
4-
let ascii: number;
5-
let new_code: number;
64

75
return word.split("").map(caesar => {
8-
new_code = 0;
9-
ascii = caesar.charCodeAt(0);
6+
const ascii: number = caesar.charCodeAt(0);
7+
const new_code: number = ascii + shift;
108
if (ascii >= 65 && ascii <= 90) {
11-
new_code = ascii + shift;
12-
if (new_code < 65) {new_code += 26}
13-
if (new_code > 90) {new_code -= 26}
14-
return String.fromCharCode(new_code)
9+
if (new_code < 65) {return String.fromCharCode(new_code + 26)}
10+
if (new_code > 90) {return String.fromCharCode(new_code - 26)}
11+
else return String.fromCharCode(new_code)
1512
} else if (ascii >= 97 && ascii <= 122) {
16-
new_code = ascii + shift;
17-
if (new_code < 97) {new_code += 26}
18-
if (new_code > 122) {new_code -= 26}
13+
if (new_code < 97) {return String.fromCharCode(new_code + 26)}
14+
if (new_code > 122) {return String.fromCharCode(new_code - 26)}
1915
return String.fromCharCode(new_code)
2016
} else return caesar;
2117
}).join('');

0 commit comments

Comments
 (0)