-
Notifications
You must be signed in to change notification settings - Fork 57
feat: add solution for day 04 #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA new TypeScript file has been added to the daily challenges directory, introducing a poker scoring system. The implementation defines two types: Changes
Sequence DiagramsequenceDiagram
participant Func as calculatePokerScore
participant Players as Player[]
participant Scorer as Scoring Logic
participant Ranker as Ranking System
Func->>Players: Receive player array
Players->>Scorer: Pass player details
Scorer-->>Scorer: Calculate score per player
Scorer->>Ranker: Generate ranked list
Ranker-->>Func: Return sorted ranking
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
daily-challenges/2025-01/04/hunghoang3110.ts
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
daily-challenges/2025-01/04/hunghoang3110.ts
[error] 13-13: This let declares a variable that is only assigned once.
'arrayRanked' is never reassigned.
Safe fix: Use const instead.
(lint/style/useConst)
🔇 Additional comments (3)
daily-challenges/2025-01/04/hunghoang3110.ts (3)
1-5
: Good use of a custom type for players
This structure adequately captures the player's name, rank, and chip count.
7-10
: Clear definition for ranked data
Defining a separateRanked
type clarifies the return type for your computed scoring function.
55-56
: Efficient sorting and return
Returning the sorted array in descending order is straightforward and effective. Good job!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
daily-challenges/2025-01/04/hunghoang3110.ts
(1 hunks)
🔇 Additional comments (2)
daily-challenges/2025-01/04/hunghoang3110.ts (2)
25-34
: Wrap the logic for negative or excessive chips in validation (if applicable).The scoring formula uses
player.chips * 10
directly. If negative or extremely large chip values are possible, we could inadvertently produce unexpected scores. Consider enforcing valid chips range or at least logging a warning.
12-23
: 🧹 Nitpick (assertive)Consider simplifying the data structure.
Since you’re storing static rank-value pairs, an object literal or a
Record
type might be more straightforward than aMap
. This is a minor suggestion and a matter of personal preference.-const rankScores = new Map<string, number>([ - ['Royal Flush', 1000], - ['Straight Flush', 750], - ... -]); +const rankScores: Record<string, number> = { + 'Royal Flush': 1000, + 'Straight Flush': 750, + ... +};Likely invalid or redundant comment.
type Ranked = { | ||
name: string; | ||
score: number; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider using an interface for flexibility.
Declaring Ranked
as an interface (instead of a type alias) can empower extension with additional properties if needed in the future. However, this is optional and purely stylistic.
type Player = { | ||
name: string; | ||
rank: string; | ||
chips: number; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Use a union type for the rank property.
Currently, the rank
property of Player
is a string
, which can introduce runtime ambiguity if an unrecognized rank is provided. Consider using a union type (e.g., 'Royal Flush' | 'Straight Flush' | ...
) to keep the code self-documenting and guard against invalid poker hands.
-type Player = {
- name: string;
- rank: string;
- chips: number;
-};
+type PlayerRank =
+ | 'Royal Flush'
+ | 'Straight Flush'
+ | 'Four of a Kind'
+ | 'Full House'
+ | 'Flush'
+ | 'Straight'
+ | 'Three of a Kind'
+ | 'Two Pair'
+ | 'One Pair'
+ | 'High Card';
+
+type Player = {
+ name: string;
+ rank: PlayerRank;
+ chips: number;
+};
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
type Player = { | |
name: string; | |
rank: string; | |
chips: number; | |
}; | |
type PlayerRank = | |
| 'Royal Flush' | |
| 'Straight Flush' | |
| 'Four of a Kind' | |
| 'Full House' | |
| 'Flush' | |
| 'Straight' | |
| 'Three of a Kind' | |
| 'Two Pair' | |
| 'One Pair' | |
| 'High Card'; | |
type Player = { | |
name: string; | |
rank: PlayerRank; | |
chips: number; | |
}; |
Summary by CodeRabbit