Merge pull request #48 from christianbender/changed_caesarsCipher

removed switch construct and put in a if-construct.
This commit is contained in:
Christian Bender
2018-03-30 16:18:39 +02:00
committed by GitHub

View File

@ -18,19 +18,14 @@ function rot13(str) {
for (let i =0; i < strLength; i++) { for (let i =0; i < strLength; i++) {
const char = str.charCodeAt(i); const char = str.charCodeAt(i);
switch(true) { if (char < 65 || (char > 90 && char < 97) || char > 122) {
// Check for non-letter characters
case char < 65 || (char > 90 && char < 97) || char > 122:
response.push(str.charAt(i)); response.push(str.charAt(i));
break; } else if ((char > 77 && char <= 90 ) || (char > 109 && char <= 122)) {
// Letters from the second half of the alphabet
case (char > 77 && char <= 90 ) || (char > 109 && char <= 122):
response.push(String.fromCharCode(str.charCodeAt(i) - 13)); response.push(String.fromCharCode(str.charCodeAt(i) - 13));
break; } else {
// Letters from the first half of the alphabet
default:
response.push(String.fromCharCode(str.charCodeAt(i) + 13)); response.push(String.fromCharCode(str.charCodeAt(i) + 13));
} }
} }
return response.join(''); return response.join('');
} }