Skip to content

Instantly share code, notes, and snippets.

@jasonwaters
Created October 17, 2016 18:26
Show Gist options
  • Select an option

  • Save jasonwaters/d27c96c969d743ded4b350c54f551810 to your computer and use it in GitHub Desktop.

Select an option

Save jasonwaters/d27c96c969d743ded4b350c54f551810 to your computer and use it in GitHub Desktop.
// SLC -> AUS -> LAX -> JFK -> SJC
let passes = [
{depart: 'JFK', arrive: 'SJC'},
{depart: 'LAX', arrive: 'JFK'},
{depart: 'AUS', arrive: 'LAX'},
{depart: 'SLC', arrive: 'AUS'}
];
let departures = [];
let destinations = [];
let start, finish;
passes.forEach(pass => {
departures.push(pass.depart);
destinations.push(pass.arrive);
if(!destinations.includes(pass.depart)) {
start = pass.depart;
}
if(!departures.includes(pass.arrive)) {
finish = pass.arrive;
}
});
console.log(`${start} -> ${finish}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment