Liliana797979

store provition1 - fundamentals

Jul 2nd, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function storeProvision(store = [], delivery = []) {
  2.   let result = [];
  3.   class Store {
  4.     constructor(productName, quantity) {
  5.       this.productName = productName;
  6.       this.quantity = quantity;
  7.     }
  8.   }
  9.   for (let i = 0; i < store.length; i++) {
  10.     if (i % 2 !== 0) {
  11.       store[i] = +store[i];
  12.     }
  13.   }
  14.   for (let i = 0; i < delivery.length; i += 2) {
  15.     if (store.includes(delivery[i])) {
  16.       let index = store.indexOf(delivery[i]);
  17.       store[index + 1] += +delivery[i + 1];
  18.     } else {
  19.       store.push(delivery[i]);
  20.       store.push(delivery[i + 1]);
  21.     }
  22.   }
  23.  
  24.   for (let i = 0; i < store.length; i += 2) {
  25.     p = new Store(store[i], store[i + 1]);
  26.     result.push(p);
  27.   }
  28.  
  29.   for (const key of result) {
  30.     console.log(`${key.productName} -> ${key.quantity}`);
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment