Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let dataStore = new Map();
- let bottleStore = new Map();
- for (let b of input) {
- let [product,quantity] = b.split(' => ');
- let quant = Number(quantity);
- if (quant >= 1000) {
- if (!dataStore.has(product)) {
- dataStore.set(product, quant);
- } else {
- let oldQuan = dataStore.get(product);
- let totalQuant = (oldQuan) + quant;
- dataStore.set(product, totalQuant);
- }
- }
- if (quant < 1000) {
- if (!bottleStore.has(product)) {
- bottleStore.set(product, quant);
- } else {
- let oldQuan = bottleStore.get(product);
- let totalQuant = (oldQuan) + quant;
- bottleStore.set(product, totalQuant);
- }
- }
- }
- for (let [key,value] of bottleStore) {
- if (dataStore.has(key)) {
- dataStore.set(key,dataStore.get(key) + value)
- }
- }
- for (let [k,v] of dataStore) {
- console.log(`${k} => ${Math.floor(v/1000)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement