Skip to content

Commit 2d626b8

Browse files
committed
day 7
1 parent 6b5879f commit 2d626b8

File tree

9 files changed

+2146
-2
lines changed

9 files changed

+2146
-2
lines changed

puzzles/day-7/compareHands.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const compareCards = (order: string[], card1: string, card2: string): number => {
2+
const card1Value = order.indexOf(card1);
3+
const card2Value = order.indexOf(card2);
4+
5+
if (card1Value > card2Value) {
6+
return -1;
7+
} else if (card1Value < card2Value) {
8+
return 1;
9+
} else {
10+
return 0;
11+
}
12+
};
13+
14+
export const compareHands = (order: string[], hand1: string, hand2: string): number => {
15+
for (let i = 0; i < hand1.length; i++) {
16+
const comparison = compareCards(order, hand1[i], hand2[i]);
17+
if (comparison !== 0) {
18+
return comparison;
19+
}
20+
}
21+
return 0;
22+
};

0 commit comments

Comments
 (0)