09. Lowest Prices in Cities / JS Objects
Досега не ми се беше случвало да не загрея какво се иска от мен :) Не ми минава един от тестовете и той излезе открит. Проблемът ми е, че го гледам и не разбирам защо джъдж иска резултата, който иска.
Моята функция връща като най-ниска цена "Audi - 1000 (Mexico City)". Правилното трябвало да е "Audi - 100000 (Sofia City)".
Защо?
Ето го теста:
-------------------------------------------------
Sofia City | Audi | 100000
Sofia City | BMW | 100000
Sofia City | Mitsubishi | 10000
Sofia City | Mercedes | 10000
Sofia City | NoOffenseToCarLovers | 0
Mexico City | Audi | 1000
Mexico City | BMW | 99999
New York City | Mitsubishi | 10000
New York City | Mitsubishi | 1000
Mexico City | Audi | 100000
Washington City | Mercedes | 1000
-------------------------------------------------
Условието и пример:
-------------------------------------------------
You will be given several towns, with products and their price. You need to find the lowest price for every product and the town it is sold at for that price.
The input comes as array of strings. Each element will hold data about a town, product, and its price at that town. The town and product will be strings; the price will be a number. The input will come in the following format:
{townName} | {productName} | {productPrice}
If you receive the same town and product more than once, you should update the old value with the new one.
As output you must print each product with its lowest price and the town at which the product is sold at that price. If two towns share the same lowest price, print the one that was entered first.
The output, for every product, should be in the following format:
{productName} -> {productLowestPrice} ({townName})
The order of output is – order of entrance. See the examples for more info.
Input |
Output |
Sample Town | Sample Product | 1000 Sample Town | Orange | 2 Sample Town | Peach | 1 Sofia | Orange | 3 Sofia | Peach | 2 New York | Sample Product | 1000.1 New York | Burger | 10 |
Sample Product -> 1000 (Sample Town) Orange -> 2 (Sample Town) Peach -> 1 (Sample Town) Burger -> 10 (New York) |
Кода ми:
--------------------------------------------------
http://pastebin.com/4eZYV0JZ
Да, явно е това. Обаче защо градът да стане София?
Както ти е написал колегата понеже след края на четене на входа имаш 2 града със Audi за 100000, трябва да изпечаташ града който е дошъл първи от входа който е Sofia, всичко си го пише в условието.
As output you must print each product with its lowest price and the town at which the product is sold at that price. If two towns share the same lowest price, print the one that was entered first.
Ясно, т.е. трябва съвсем друго нещо да правя в тази задача от това, което правя. Мерси.