Created
October 17, 2016 18:26
-
-
Save jasonwaters/d27c96c969d743ded4b350c54f551810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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