Skip to content

Instantly share code, notes, and snippets.

@danielsousaio
Last active July 18, 2020 01:12
Show Gist options
  • Save danielsousaio/405c0468974c3db9b1c637522a04ae75 to your computer and use it in GitHub Desktop.
Save danielsousaio/405c0468974c3db9b1c637522a04ae75 to your computer and use it in GitHub Desktop.
let cards = {
Q: { colorCards: "lol", equity: 42 },
A: { colorCards: "lol", equity: 42 }
};
let defaultHand = {
colorCards: "AAA",
equity: 40
};
function getHand(cards, hand) {
return Object.assign(cards, {
get [hand]() {
return cards[hand] || defaultHand;
}
})[hand];
}
console.log(getHand(cards, "Q"));
console.log(getHand(cards, "A"));
console.log(getHand(cards, "J"));
console.log(getHand(cards, "K"));
console.log(getHand(cards, "Q").colorCards);
console.log(getHand(cards, "A").colorCards);
console.log(getHand(cards, "J").colorCards);
console.log(getHand(cards, "K").colorCards);
// { colorCards: 'lol', equity: 42 }
// { colorCards: 'lol', equity: 42 }
// { colorCards: 'AAA', equity: 40 }
// { colorCards: 'AAA', equity: 40 }
// lol
// lol
// AAA
// AAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment