If str [ i ] is between 0 and 9 and i is the last occurence in str
else if ( ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) && num [ str [ i ] . charCodeAt ( 0 ) - 48 ] == i ) { let occ = str [ i ] . charCodeAt ( 0 ) - 48 ; while ( occ -- ) { res += str [ i ] ; } } else { res += str [ i ] ; } }