separate digits and alphabets
for ( var i = 0 ; i < n ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) digitSum += ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; else { alphabetSum += ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ) ; alphabetSum %= 26 ; } }