tally = 0
str.each_char do |c|
when "X" then tally += 1
when "O" then tally -= 1
Shorter solutions, but this only loops through the string once which might be nice for enormous strings.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.