Skip to content

Instantly share code, notes, and snippets.

@leomastoras
Last active April 20, 2024 18:31
Show Gist options
  • Save leomastoras/9a0dc4d792dccf52297f101bac9b7999 to your computer and use it in GitHub Desktop.
Save leomastoras/9a0dc4d792dccf52297f101bac9b7999 to your computer and use it in GitHub Desktop.
Deck of cards
Array.prototype.hasOwnProperty('shuffle') || Object.defineProperty(Array.prototype, 'shuffle', {
value: function() { return this.sort(() => Math.random() - .5); }
});
let deck = [...'♠♣♥♦'].flatMap(s => ('A,'+[...Array(11).keys()].slice(2)+',J,Q,K').split(/,/).map(c => c + s));
console.log(deck);
console.log(deck.shuffle());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment