cards
Adds the CardDeck class, a stack-like collection of objects that
supports operations typical of a deck of cards, such as shuffling, drawing from,
and discarding to.
Creates a new, empty deck of cards.
Returns a string consisting of a comma separated list of the cards in
this card deck.
returns a string listing the contents of this CardDeck
Creates a new deck, using items from an array to populate it.
arrayLikeObject | an array or array-like object to copy from |
returns a card deck consisting of objects copied from arrayLikeObject
Shuffles the cards in a deck into a random order.
Draws the top card off the deck. This removes the card from the deck;
to return the card, use CardDeck.discard. Drawing from an
empty deck throws an exception.
removes and returns the top card from the deck
Searches the deck for the first card for which matchFunction(card)
returns true. If a matching card is found, removes it from the deck and
returns it. If there is no matching card, returns null.
matchFunction | a function that takes a card and returns true if it is the type of card you wish to draw |
returns the matching card (which is removed from the deck), or null
Adds card to the bottom of the deck.
It is not required that card have previously been drawn from
the deck. If copies is defined, then
that many copies are added, all identical.
The default value is 1.
card | the card to add to the deck |
copies | the optional number of copies to add to the deck |
places card(s) on the bottom of the deck
Returns a card from the deck without removing it. If index
is not defined, then the card at the top of the deck is returned.
Otherwise, if index is 0 or positive, then the card at position
index is returned, where a position of 0 is the top of the deck,
1 is the next card from the top, and so on. If index is negative,
then the cards are counted from the bottom of the deck: -1 is the last card,
-2 is the penultimate card, and so on.
index | the position of the card to peek at within the deck |
returns the card at index
Pulls a card from the deck from any position. The card at the requested position
is removed from the deck and returned. As with CardDeck.peek(),
a negative index may be used to count from the bottom of the deck.
If called without an index argument, this method is equivalent to
CardDeck.draw().
index | the optional position of the card to remove from the deck |
returns and removes the card at index
Returns the number of cards currently in this deck.
Contents