7 kyu

Airport itinerary

273 of 524antenor

Description:

Travel itinerary

When you travel around the world you pass though different airports.

TRN -> FCO -> JFK

And then return back to home

JFK - TRN

In order to propose the unique list of airports that your trip uses we have to create an itinerary feature that can compress the list of airports including only the list of unique in/out combination.

For example, a trip with:

[TRN-FCO] [FCO-JFK] [JFK-TRN]

Should be represented as:

TRN-FCO-JFK-TRN

That is the unique list of airport steps.

Now in our database we save the travel as a list of objects with in/out properties and you will receive that list always sorted in the right way.

[
  {in: "TRN", out: "FCO"},
  {in: "FCO", out: "JFK"},
  {in: "JFK", out: "FCO"}
]

Now we have to create a helper function itinerary for JS that extract the unique airport list:

travel = itinerary([
  {in: "TRN", out: "FCO"},
  {in: "FCO", out: "JFK"},
  {in: "JFK", out: "FCO"}
]); // TRN-FCO-JFK-FCO

Or a helper class Route for C#/C++:

public class Route
{
  public string In;
  public string Out;
}
class Route
{
public:
    std::string in;
    
    std::string out;
    
    Route(std::string in, std::string out)
    {
        this->in = in;
        this->out = out;
    }
    
    ~Route() { };
};
Strings
Fundamentals

More By Author:

Check out these other kata created by antenor

Stats:

CreatedAug 7, 2016
PublishedAug 7, 2016
Warriors Trained1027
Total Skips77
Total Code Submissions1657
Total Times Completed524
JavaScript Completions273
C# Completions74
C++ Completions144
Elixir Completions53
Total Stars15
% of votes with a positive feedback rating87% of 139
Total "Very Satisfied" Votes110
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes7
Total Rank Assessments8
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • antenor Avatar
  • Dentzil Avatar
  • user5036852 Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
Ad