Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cappyJuice(input) {
- const quantities = {};
- const bottles = {};
- input.forEach((line) => {
- const tokens = line.split(' => ');
- const [fruit, quantity] = tokens;
- if (!quantities.hasOwnProperty(fruit)) {
- quantities[fruit] = 0;
- }
- quantities[fruit] += Number(quantity);
- if (quantities[fruit] >= 1000) {
- bottles[fruit] = parseInt(quantities[fruit] / 1000);
- }
- });
- Object.keys(bottles).forEach((key) => {
- console.log(`${key} => ${bottles[key]}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement