Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let map = new Map();
- for (let string of input) {
- let tokens = string.split(' ');
- let product = tokens[0];
- let quantity = Number(tokens[1]);
- if (!map.has(product)) {
- map.set(product, quantity);
- } else {
- let currQuantity = map.get(product);
- let newQuantity = currQuantity += quantity;
- map.set(product, newQuantity);
- }
- }
- for (let key in map) {
- console.log(`${key} -> ${map[key]}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment