removed switch construct and put in a if-construct.

This commit is contained in:
Christian Bender
2018-03-30 16:16:12 +02:00
parent b9d749acd2
commit bceb750f76

View File

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