didkoslawow

Untitled

Jan 25th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function storeProvisions(storeProducts, purchasedProducts) {
  2.     let product = '';
  3.     let quantity = 0;
  4.     const finalList = {};
  5.  
  6.     const storeLength = storeProducts.length;
  7.     for (let i = 0; i < storeProducts.length; i += 2) {
  8.         product = storeProducts[i];
  9.         quantity = Number(storeProducts[i+1]);
  10.         finalList[product] = quantity;
  11.     }
  12.  
  13.     const purchasedLength = purchasedProducts.length;
  14.     for (let j = 0; j < purchasedLength; j += 2) {
  15.         if (purchasedProducts[j] in finalList) {
  16.             finalList[purchasedProducts[j]] += Number(purchasedProducts[j+1]);
  17.         } else {
  18.             finalList[purchasedProducts[j]] = Number(purchasedProducts[j+1]);
  19.         }
  20.     }
  21.    
  22.     for (let [key, value] of Object.entries(finalList)) {
  23.         console.log(`${key} -> ${value}`);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment