DEV Community

Discussion on: Daily Challenge #29 - Xs and Os

Collapse
 
phallstrom profile image
Philip Hallstrom

Ruby

def xo(str)
  tally = 0
  str.each_char do |c|
    case c.upcase
    when "X" then tally += 1
    when "O" then tally -= 1
    end
  end
  tally.zero?
end

Shorter solutions, but this only loops through the string once which might be nice for enormous strings.