Skip to content

Instantly share code, notes, and snippets.

@kleytonmr
Last active June 1, 2020 03:06
Show Gist options
  • Save kleytonmr/f9e35a4c249cbb417498e44a584af533 to your computer and use it in GitHub Desktop.
Save kleytonmr/f9e35a4c249cbb417498e44a584af533 to your computer and use it in GitHub Desktop.
Product
# arr.product( ‹ arrays›* ) → result_array
# arr.product( ‹ arrays›* ) ‹{|combination| … }› → arr
suits = %w[ C D H S ]
ranks = [ *2..10, *%w{ J Q K A }]
card_deck = suits.product(ranks).shuffle
card_deck.first(13) # => [["H", "Q"], ["D", 7], ["S", "A"], ["S", "J"],
# .. ["D", 2], ["S", 10], ["D", 4], ["S", 9], ["C", 7],
# .. ["C", 4], ["H", 5], ["D", 5], ["S", 4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment