didkoslawow

Untitled

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