Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- const resources = {};
- args.forEach((element, index) => {
- if (index % 2 === 0) {
- if (!Object.prototype.hasOwnProperty.call(resources, element)) {
- resources[element] = 0;
- }
- } else if (Object.prototype.hasOwnProperty.call(resources, args[index - 1])) {
- resources[args[index - 1]] += Number(element);
- }
- });
- Object.entries(resources).forEach((element) => {
- const [resource, quantity] = element;
- console.log(`${resource} -> ${quantity}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement