createHotel
Creates and initializes a new hotel object with rooms, reservations, and history.Function Signature
Parameters
The name of the hotel
Array of room objects. Each room should contain:
number(number): Room numbertype(string): Room type (‘single’, ‘double’, or ‘suite’)pricePerNight(number): Price per night for the roomstatus(string): Current room status (‘available’, ‘occupied’, etc.)
Return Value
The initialized hotel object
Example
Expected Output
The hotel object is initialized with mock data for reservations and history from JSON imports.
searchAvailableRooms
Searches for available rooms of a specific type within a given date range.Function Signature
Parameters
The hotel object to search within
Check-in date in ISO format (e.g., ‘2026-03-19’)
Check-out date in ISO format (e.g., ‘2026-03-22’)
Type of room to search for. Valid values:
'single'- Single room'double'- Double room'suite'- Suite room
How It Works
The function performs three filtering steps:- Filter by Type: Filters all hotel rooms to match the requested
roomType - Get Reserved Rooms: Calls
getReservedRoomsByDate()to get a Set of room numbers that are reserved (with status ‘confirmed’) for the specified date range - Filter Available: Returns only rooms of the requested type that are NOT in the reserved rooms set
Return Value
Array of available room objects matching the criteria
Example
Expected Output
Only rooms with status ‘confirmed’ in reservations are considered as reserved. Cancelled or checked-out reservations don’t affect availability.
Related Functions
This function uses the following helper functions fromutils.js:
getReservedRoomsByDate()- Returns a Set of room numbers reserved for the date range (main.js:109)