feat(SW-717) make reduce more understandable

This commit is contained in:
Pontus Dreij
2025-02-07 08:31:40 +01:00
parent e00cea4646
commit dcd45ee31d
3 changed files with 37 additions and 22 deletions

View File

@@ -8,12 +8,17 @@ import type { RoomConfiguration } from "@/types/trpc/routers/hotel/roomAvailabil
export function filterDuplicateRoomTypesByLowestPrice(
roomConfigurations: RoomConfiguration[]
): RoomConfiguration[] {
const roomTypeCount = roomConfigurations.reduce(
(acc, room) => {
acc[room.roomType] = (acc[room.roomType] || 0) + 1
return acc
const roomTypeCount = roomConfigurations.reduce<Record<string, number>>(
(roomTypeTally, currentRoom) => {
const currentRoomType = currentRoom.roomType
const currentCount = roomTypeTally[currentRoomType] || 0
return {
...roomTypeTally,
[currentRoomType]: currentCount + 1,
}
},
{} as Record<string, number>
{}
)
const duplicateRoomTypes = new Set(