Advertisement
braveheart1989

Cappy Juice

Dec 14th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let dataStore = new Map();
  3.     let bottleStore = new Map();
  4.     for (let b of input) {
  5.         let [product,quantity] = b.split(' => ');
  6.         let quant = Number(quantity);
  7.         if (quant >= 1000) {
  8.             if (!dataStore.has(product)) {
  9.                 dataStore.set(product, quant);
  10.             } else {
  11.                 let oldQuan = dataStore.get(product);
  12.                 let totalQuant = (oldQuan) + quant;
  13.                 dataStore.set(product, totalQuant);
  14.             }
  15.         }
  16.         if (quant < 1000) {
  17.             if (!bottleStore.has(product)) {
  18.                 bottleStore.set(product, quant);
  19.             } else {
  20.                 let oldQuan = bottleStore.get(product);
  21.                 let totalQuant = (oldQuan) + quant;
  22.                 bottleStore.set(product, totalQuant);
  23.             }
  24.         }
  25.     }
  26.     for (let [key,value] of bottleStore) {
  27.         if (dataStore.has(key)) {
  28.             dataStore.set(key,dataStore.get(key) + value)
  29.         }
  30.     }
  31.     for (let [k,v] of dataStore) {
  32.         console.log(`${k} => ${Math.floor(v/1000)}`);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement