From bceb750f76fda3b4b7cf49b81e1cfd5c258bd28d Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Fri, 30 Mar 2018 16:16:12 +0200 Subject: [PATCH] removed switch construct and put in a if-construct. --- Ciphers/caesarsCipher.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Ciphers/caesarsCipher.js b/Ciphers/caesarsCipher.js index af6369c6d..5dc4af5d8 100644 --- a/Ciphers/caesarsCipher.js +++ b/Ciphers/caesarsCipher.js @@ -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(''); }