Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function time(input) {
- let allCountry = {};
- for (const string of input) {
- let [country, town, cost] = string.split(' > ');
- cost = Number(cost);
- town = town[0].toLocaleUpperCase() + town.substr(1);
- if (!allCountry.hasOwnProperty(country)) {
- allCountry[country] = {};
- }
- if (!allCountry[country].hasOwnProperty(town)) {
- allCountry[country][town] = cost;
- }
- if (cost < allCountry[country][town]) {
- allCountry[country][town] = cost;
- }
- }
- let result = Object.keys(allCountry).sort();
- for (const string of result) {
- let output = `${string} ->`;
- let inner = Object.keys(allCountry[string]).sort(function (x,y) {
- return allCountry[string][x]-allCountry[string][y];
- });
- for (const string1 of inner) {
- output+=` ${string1} -> ${allCountry[string][string1]}`;
- }
- console.log(output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement