kstoyanov

03. Store Provision js fundamentals

Jul 1st, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(...args) {
  2.   const localStoreStock = args[0];
  3.   const orderedStock = args[1];
  4.  
  5.   const products = {};
  6.  
  7.   localStoreStock.forEach((element, index) => {
  8.     if (index % 2 === 0) {
  9.       products[element] = Number(localStoreStock[index + 1]);
  10.     }
  11.   });
  12.  
  13.   orderedStock.forEach((element, index) => {
  14.     if (products[element] !== undefined) {
  15.       products[element] += Number(orderedStock[index + 1]);
  16.     } else if (index % 2 === 0) {
  17.       products[element] = Number(orderedStock[index + 1]);
  18.     }
  19.   });
  20.  
  21.   Object.keys(products).map((element) => console.log(`${element} -> ${products[element]}`));
  22. }
Add Comment
Please, Sign In to add comment