Skip to content

Instantly share code, notes, and snippets.

@MisterBrash
Created May 3, 2024 12:59
Show Gist options
  • Save MisterBrash/c2c448e5177918f5718518075183f332 to your computer and use it in GitHub Desktop.
Save MisterBrash/c2c448e5177918f5718518075183f332 to your computer and use it in GitHub Desktop.
Unit 3 Summative too easy? Give this a try...

52 Pickup

Note: This is an optional challenge, for students who found the Unit 3 Summative a little too easy.


Playing Cards:

A standard deck of cards is comprised of four suits (Hearts, Diamonds, Clubs, and Spades) and each suit has the cards 2 through 10, Jack, Queen, King, and Ace.

One way of storing each card is through two-character strings. For example "AH" is the Ace of Hearts and "2D" is the 2 of diamonds, "8S" is the 8 of spades, etc. (It is worth noting that this is an amateur way of storing the data, but it still works!)
Another way is use the ASCII characters for the suits: ♥ ♦ ♣ ♠

A Deck of Cards:

This means that a deck of cards can be created using these strings:
deck = ["2D", "2H", "2C", "2S", "3D", "3H", ... , "AC", "AS"]
or deck = ["2♦", "2♥", "2♣", "2♠", "3♦", "3♥", ... , "A♣", "A♠"] ``

The array deck would have a length of 52 when complete.


Task #1:

Create the function createDeck() that returns a complete array of 52 cards, as described above. The deck should be ordered from 2 to ACE and the suit order should be D, H, C, S. The array will be created programatically, not hard-coded.

Task #2:

Create the function shuffle(deck). This function receives a deck of cards and shuffles the order of that deck - returning the shuffled deck. Keep in mind that the method you use for shuffling must be random so that it returns a new shuffled order each time.

Task #3:

Cards are used to play games. When you play a game, you deal cards to people. Create the function deal(deck, num) that deals out cards (or one card). This function returns an array of cards of length num, having removed those cards from the deck. To clarify, the arguments to the function are the deck to deal from and the number of cards to deal. It removes those cards from the deck, returning an array of the cards that were dealt. Even if only one card is being dealt - it is in an array.

Task #4:

Cards can be put into a deck, but only if the deck doesn't already have that card! Create the function insert(deck, card) that:

  • Checks the deck to see if card is already in it.
    • If the card is not already in the deck, it inserts the card at the end. If you want to shuffle it after inserting, that's up to you. Return true.
    • If the card is already in the deck, do nothing and return false.

Task #5:

A deck of cards is only useful if it is complete (has all the proper cards). Create the function isComplete(deck) that receives a deck of cards and checks to see if it has all the appropriate cards for a complete deck. It will return true if the deck is complete and false otherwise.











Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment