Liliana797979

store provition2 - fundamentals

Jul 2nd, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printStock(stock, orderedProducts) {
  2.     let currentStock = {};
  3.  
  4.     stock.forEach((e, index) => {
  5.         if (index % 2 == 0) {
  6.             if (!currentStock[e]) {
  7.                 currentStock[e] = Number(stock[index + 1]);
  8.             } else {
  9.                 currentStock[e] += Number(stock[index + 1]);
  10.             }
  11.         }
  12.     });
  13.  
  14.     orderedProducts.forEach((el, index) => {
  15.         if (index % 2 == 0) {
  16.             if (!currentStock[el]) {
  17.                 currentStock[el] = Number(orderedProducts[index + 1]);
  18.             } else {
  19.                 currentStock[el] += Number(orderedProducts[index + 1]);
  20.             }
  21.         }
  22.     });
  23.  
  24.     Object.keys(currentStock)
  25.         .forEach(product => console.log(`${product} -> ${currentStock[product]}`));
  26. }
Advertisement
Add Comment
Please, Sign In to add comment