Skip to content

Instantly share code, notes, and snippets.

@TracyGJG
Last active February 16, 2023 08:28
Show Gist options
  • Save TracyGJG/a530d2de883634cfcfe317d2a88fec65 to your computer and use it in GitHub Desktop.
Save TracyGJG/a530d2de883634cfcfe317d2a88fec65 to your computer and use it in GitHub Desktop.
Poker stats calculator
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,
};
}
@TracyGJG
Copy link
Author

Renamed some properties to align with project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment