File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -18,19 +18,14 @@ function rot13(str) {
18
18
for ( let i = 0 ; i < strLength ; i ++ ) {
19
19
const char = str . charCodeAt ( i ) ;
20
20
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 ) ) ;
33
27
}
28
+
34
29
}
35
30
return response . join ( '' ) ;
36
31
}
You can’t perform that action at this time.
0 commit comments