Created
July 19, 2021 22:57
-
-
Save Ebazhanov/9787491269c421d6e5099bfe41e8ea47 to your computer and use it in GitHub Desktop.
This file contains 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
function getRoute (tickets) { | |
const route = tickets.pop(); | |
let i = 0; | |
while (i < tickets.length) { | |
if (route[0] === tickets[i][1]) { | |
route.unshift(tickets[i][0]); | |
i = 0; | |
} else if (route[route.length - 1] === tickets[i][0]) { | |
route.push(tickets[i][1]); | |
i = 0; | |
} else i++; | |
} | |
return route.toString(); | |
} | |
const result = getRoute([["JPN", "PHL"], ["BRA", "UAE"], ["USA", "BRA"], ["UAE", "JPN"]]); | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment