3. Functions
Activity 3.01: Building a Flight Booking System with Functions
Solution:
- Start with the stubs provided in code samples. We have three files:
index.ts
,bookings.ts
, andflights.ts
. Theindex.ts
file is a bit abstract and will just represent some of the transactions we push into our system.bookings.ts
handles the user-facing activities of managing a booking, andflights.ts
is the back office of filling up flights and making sure that everybody has a seat. - The
index.ts
file won't change unless you feel like changing it and adding some new scenarios. Let's run it without adding any code:npx ts-node index.ts Not implemented!
So we have work to do. Several functions are not yet implemented. Let's start by looking at
flights.ts
. There is a partial implementation there as we have an interface calledFlights
that describes the attributes of a flight, a list of available flights implementing that interface, and even a method to fetch the flights, called...