Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let bottles = new Map();
- let juiceStorage = {};
- input.forEach(juice => {
- let [type, quantity] = juice.split(' => ');
- quantity = Number(quantity);
- if (!juiceStorage[type]) {
- juiceStorage[type] = quantity;
- } else {
- juiceStorage[type] += quantity;
- }
- if (juiceStorage[type] >= 1000) {
- if (!bottles.has(type)) {
- bottles.set(type, []);
- bottles.get(type).push(quantity);
- } else {
- bottles.get(type).push(quantity);
- }
- }
- });
- Array.from(bottles).forEach(el => {
- let quantity = parseInt((el[1].reduce((a, b) => a + b, 0)) / 1000);
- console.log(`${el[0]} => ${quantity}`);
- });
- }
- solve(['Kiwi => 234',
- 'Pear => 2345',
- 'Watermelon => 3456',
- 'Kiwi => 4567',
- 'Pear => 5678',
- 'Watermelon => 6789'
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement