Skip to content

the best commit message ever. written by cleop #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion lib/dojo/hand.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,38 @@ defmodule Dojo.Hand do
evaluate(cards)
end

defp evaluate(_), do: :high_card
defp sort_cards(cards) do
Enum.sort(cards)
end

defp evaluate(hand) do
sorted_hand = sort_cards(hand)
[first_card | tail] = sorted_hand
check_suit(first_card, tail, hand)
end

defp check_suit(card, [], hand) do
# suit is all the same
:flush
end

defp check_suit(first_card, list, hand) do
[next_card | rest] = list
case first_card.suit == next_card.suit do
true ->
check_suit(next_card, rest, hand)
false ->
# not all suits are same go here
:high_card
end
end

end

# cards = [
# %{rank: 13, suit: :hearts},
# %{rank: 10, suit: :hearts},
# %{rank: 11, suit: :hearts},
# %{rank: 12, suit: :hearts},
# %{rank: 14, suit: :hearts}
# ]