Coding Challenge: Create Algebraic Data Type
Let's create an algebraic data type.
Problem statement
In this challenge, create an algebraic data type (sum type) for a vehicle. The type of vehicle will be either a car or a bicycle. A car will have two properties: mileage
and numberOfSeats,
both properties of type number
. On the other hand, a bicycle has a single property called luggageRack
of type boolean.
Try it yourself
You can implement your solution in the code widget provided below.
Get hands-on with 1400+ tech skills courses.