const evaluateHand = (hand) => { const cards = hand.split('').sort((a, b) =>…
Jump to turn (6)
- 1const evaluateHand = (hand) => { const cards = hand.split('').sort((a, b) => car
- 2use the latest js and es features
- 3Directions: State the prepositional phrases below. Remember that prepositional p
- 4Oh no! St.Nick is at the dinner table ready to recount a wonderful, jolly tale a
- 5I don't see the part where st.nick has a hard time remembering the story
- 61:1 error This module could be parsed as a valid script import/unambiguous 50:19
- User
const evaluateHand = (hand) => { const cards = hand.split('').sort((a, b) => cardValueMap[b] - cardValueMap[a]); const counts = cards.reduce((acc, card) => (acc[card] = (acc[card] || 0) + 1, acc), {}); const types = Object.entries(counts).sort((a, b) => b[1] - a[1]); const sortedByFrequencyThenValue = types.flatMap(([card, count]) => Array(count).fill(card)); const rank = types[0][1] === 4 ? 1 : types[0][1] === 3 && types[1]?.[1] === 2 ? 2 : types[0][1] === 3 ? 3 : types[0][1] === 2 && types[1]?.[1] === 2 ? 4 : types[0][1] === 2 ? 5 : 6; // wtf did I do return { rank, cards: sortedByFrequencyThenValue.map(card => cardValueMap[card]) }; };
Recode this function, it is obosulutely horrendous
- Assistant