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) {
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}
You can’t perform that action at this time.
0 commit comments