Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lowestPrice(input) {
- let result = new Map();
- for (const line of input) {
- let [townName, productName, productPrice] = line.split(' | ');
- productPrice = +productPrice;
- if (!result.has(productName)) {
- result.set(productName, [townName, productPrice]);
- }
- let oldPrice = result.get(productName)[1];
- if (oldPrice > productPrice) {
- result.set(productName, [townName, productPrice])
- }
- }
- for (const key of result) {
- console.log(`${key[0]} -> ${key[1][1]} (${key[1][0]})`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment