Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function storage(arr) {
- let store = new Map();
- for (let line of arr) {
- let tokens = line.split(' ');
- let product = tokens[0];
- let quantity = Number(tokens[1]);
- if (store.has(product)) {
- let currentQuantity = store.get(product); // запазваме текущото количество
- let newQuantity = currentQuantity += quantity;
- store.set(product, newQuantity);
- } else {
- store.set(product, +quantity);
- }
- }
- for (let line of store) {
- console.log(`${line[0]} -> ${line[1]}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement