Last active
February 16, 2023 08:28
-
-
Save TracyGJG/a530d2de883634cfcfe317d2a88fec65 to your computer and use it in GitHub Desktop.
Poker stats calculator
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
const tests = [ | |
[], | |
[0], | |
[0, 0], | |
[0, 1, 2, 3, 5, 1, 2, 5, 8, 5, 1], | |
[5, 5, 5, 5], | |
[5, 5, 5, 8], | |
[5, 5, 8, 8], | |
[5, 5, 8, 13], | |
[5, 8, 8, 8], | |
[5, 8, 13, 8], | |
[5, 8, 8], | |
[5, 5, 8], | |
[5, 8, 8, 1, 2, 3], | |
]; | |
console.table(tests.map(pokerStats)); | |
function pokerStats(selectedCards) { | |
const numericCards = selectedCards.filter(card => card >= 0); | |
const lowest = Math.min(...numericCards); | |
const highest = Math.max(...numericCards); | |
const distinct = [...new Set(numericCards)].sort((a, b) => b - a); | |
const counts = distinct.map( | |
card => numericCards.filter(_card => _card === card).length | |
); | |
const commonIndex = counts.findIndex( | |
maxCount => maxCount === Math.max(...counts) | |
); | |
const consensus = distinct[commonIndex]; | |
const confidence = `${~~((counts[commonIndex] / numericCards.length) * 100)}%`; | |
return { | |
lowest, | |
highest, | |
consensus, | |
confidence, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Renamed some properties to align with project.