In Ruby. Iterate over each card and total as you go. If it's a face card, count is as 10. If it's a number card, count is as what it is. If it's an ace and the current score is below 21 and counting an ace as a 11 wouldn't push it over 21, count is as 11. Otherwise, count is a 1.
In Ruby. Iterate over each card and total as you go. If it's a face card, count is as 10. If it's a number card, count is as what it is. If it's an ace and the current score is below 21 and counting an ace as a 11 wouldn't push it over 21, count is as 11. Otherwise, count is a 1.
The examples
A possible flaw is that you should be seeing cards one at a time, instead of as a whole then deciding on how to handle aces.
A .map or .inject method could clean this up in Ruby.
Isn't
(["5", "3", "7"]) # ==> 21
wrong.