Last active
July 18, 2020 01:12
-
-
Save danielsousaio/405c0468974c3db9b1c637522a04ae75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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