Implement and export as default a function that builds an itinerary between cities.
The function takes 3 arguments:
- tree of cities
- starting city
- destination city
and returns an array of cities arranged in the same order in which they are located on the itinerary.
const tree = ['Chicago', [ ['Milwaukee'], ['Rockford'], ['Indianapolis', [ ['Fort Wayne'], ['Louisville'], ['St. Louis', [ ['Kansas City', [ ['Wichita'], ]], ['Memphis'], ]], ]], ['Columbus', [ ['Cleveland'], ['Pittsburgh'], ]], ['Des Moines'], ['Minneapolis', [ ['Sioux Falls'], ['Duluth'], ['Fargo'], ]], ]]; itinerary(tree, 'Chicago', 'Duluth'); // [ 'Chicago', 'Minneapolis', 'Duluth' ] itinerary(tree, 'Fargo', 'Rockford'); // [ 'Fargo', 'Minneapolis', 'Chicago', 'Rockford' ]
- Use the lodash lib functions
For full access to the challenge you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.