Skip to content

Commit

Permalink
question: maxPairs
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelriosoliveira committed Sep 2, 2024
1 parent 7a2a0b8 commit e575bb7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/2024/368-maxPairs/maxPairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ type ShoeSide = 'L' | 'R';
type Shoe = `${ShoeSide}-${number}`;

export function maxPairs(shoes: Shoe[]): number {
return Object.values(
shoes.reduce<Record<number, ShoeSide[]>>((map, shoe) => {
const [side, sizeStr] = shoe.split('-') as [ShoeSide, string];
const shoesMap = shoes
.map(shoe => shoe.split('-') as [ShoeSide, string])
.reduce<Record<number, ShoeSide[]>>((map, [side, sizeStr]) => {
const size = Number(sizeStr);
if (!map[size]) {
map[size] = [];
}
return { ...map, [size]: [...map[size], side] };
}, {}),
).reduce((sum, sides) => {
}, {});

return Object.values(shoesMap).reduce((sum, sides) => {
// Stryker disable next-line all
const leftCount = sides.filter(side => side === 'L').length;
const rightCount = sides.length - leftCount;
Expand Down

0 comments on commit e575bb7

Please sign in to comment.