Route Construction
OzonVKTinkoff
We have a set of tickets of the form:
[
{ from: 'London', to: 'Moscow' },
{ from: 'NY', to: 'London' },
{ from: 'Moscow', to: 'SPb' },
...
]
From these tickets, we can build a single, continuous route.
There are no loops or repetitions in the route.
You need to write a program that returns these same ticket objects
in the order they appear in the route.
Examples:
Input 1:
[
{ from: "C", to: "D" },
{ from: "B", to: "C" },
{ from: "A", to: "B" },
{ from: "D", to: "E" }
]
Output 1:
[
{ from: "A", to: "B" },
{ from: "B", to: "C" },
{ from: "C", to: "D" },
{ from: "D", to: "E" }
]
Input 2:
[
{ from: "London", to: "Moscow" },
{ from: "NY", to: "London" },
{ from: "Moscow", to: "SPb" }
]
Output 2:
[
{ from: "NY", to: "London" },
{ from: "London", to: "Moscow" },
{ from: "Moscow", to: "SPb" }
]
Input 3:
[
{ from: "London", to: "Moscow" },
{ from: "Tokio", to: "NY" },
{ from: "NY", to: "London" },
{ from: "SPb", to: "Berlin" },
{ from: "Moscow", to: "SPb" }
]
Output 3:
[
{ from: "Tokio", to: "NY" },
{ from: "NY", to: "London" },
{ from: "London", to: "Moscow" },
{ from: "Moscow", to: "SPb" },
{ from: "SPb", to: "Berlin" }
]
JavaScript•UTF-8
Run your code to see results.
Click the Run button above
Route Construction
OzonVKTinkoff
We have a set of tickets of the form:
[
{ from: 'London', to: 'Moscow' },
{ from: 'NY', to: 'London' },
{ from: 'Moscow', to: 'SPb' },
...
]
From these tickets, we can build a single, continuous route.
There are no loops or repetitions in the route.
You need to write a program that returns these same ticket objects
in the order they appear in the route.
Examples:
Input 1:
[
{ from: "C", to: "D" },
{ from: "B", to: "C" },
{ from: "A", to: "B" },
{ from: "D", to: "E" }
]
Output 1:
[
{ from: "A", to: "B" },
{ from: "B", to: "C" },
{ from: "C", to: "D" },
{ from: "D", to: "E" }
]
Input 2:
[
{ from: "London", to: "Moscow" },
{ from: "NY", to: "London" },
{ from: "Moscow", to: "SPb" }
]
Output 2:
[
{ from: "NY", to: "London" },
{ from: "London", to: "Moscow" },
{ from: "Moscow", to: "SPb" }
]
Input 3:
[
{ from: "London", to: "Moscow" },
{ from: "Tokio", to: "NY" },
{ from: "NY", to: "London" },
{ from: "SPb", to: "Berlin" },
{ from: "Moscow", to: "SPb" }
]
Output 3:
[
{ from: "Tokio", to: "NY" },
{ from: "NY", to: "London" },
{ from: "London", to: "Moscow" },
{ from: "Moscow", to: "SPb" },
{ from: "SPb", to: "Berlin" }
]
Run your code to see results.