EasyJavaScriptTypeScript
Union & Literal Types — Direction & Status
TypeScriptTypesUnions
Use literal types and union types to build a small routing helper.
Implement solve(direction, speed) where:
directionis one of:"north" | "south" | "east" | "west"speedis one of:"slow" | "fast"- Returns a string:
"{direction} at {speed} speed"
Also implement isCardinal(direction) which returns true if the direction is one of the four cardinal directions, false otherwise.
Examples
solve("north", "fast")→"north at fast speed"isCardinal("north")→trueisCardinal("diagonal")→false
Sample tests
Test #1solve — north fast
Input: ["solve","north","fast"]
Output: "north at fast speed"
Test #2solve — west slow
Input: ["solve","west","slow"]
Output: "west at slow speed"
Test #3isCardinal — north is cardinal
Input: ["isCardinal","north"]
Output: true
Test #4isCardinal — diagonal is not cardinal
Input: ["isCardinal","diagonal"]
Output: false