Skip to content

Commit bceb750

Browse files
author
Christian Bender
committed
removed switch construct and put in a if-construct.
1 parent b9d749a commit bceb750

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Ciphers/caesarsCipher.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@ function rot13(str) {
1818
for (let i =0; i < strLength; i++) {
1919
const char = str.charCodeAt(i);
2020

21-
switch(true) {
22-
// Check for non-letter characters
23-
case char < 65 || (char > 90 && char < 97) || char > 122:
24-
response.push(str.charAt(i));
25-
break;
26-
// Letters from the second half of the alphabet
27-
case (char > 77 && char <= 90 ) || (char > 109 && char <= 122):
28-
response.push(String.fromCharCode(str.charCodeAt(i) - 13));
29-
break;
30-
// Letters from the first half of the alphabet
31-
default:
32-
response.push(String.fromCharCode(str.charCodeAt(i) + 13));
21+
if (char < 65 || (char > 90 && char < 97) || char > 122) {
22+
response.push(str.charAt(i));
23+
} else if ((char > 77 && char <= 90 ) || (char > 109 && char <= 122)) {
24+
response.push(String.fromCharCode(str.charCodeAt(i) - 13));
25+
} else {
26+
response.push(String.fromCharCode(str.charCodeAt(i) + 13));
3327
}
28+
3429
}
3530
return response.join('');
3631
}

0 commit comments

Comments
 (0)