If a character from L is encountered , then the answer variable is incremented by the value obtained by using the mentioned formula and count is set to 0
if ( freq [ x . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] > 0 ) { ans = ans + parseInt ( ( count * count + count ) / 2 ) ; count = 0 ; } else count ++ ; }