Advertisement
kstoyanov

08. A Miner Task js fundamentals

Jul 13th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const resources = {};
  3.  
  4.   args.forEach((element, index) => {
  5.     if (index % 2 === 0) {
  6.       if (!Object.prototype.hasOwnProperty.call(resources, element)) {
  7.         resources[element] = 0;
  8.       }
  9.     } else if (Object.prototype.hasOwnProperty.call(resources, args[index - 1])) {
  10.       resources[args[index - 1]] += Number(element);
  11.     }
  12.   });
  13.  
  14.   Object.entries(resources).forEach((element) => {
  15.     const [resource, quantity] = element;
  16.  
  17.     console.log(`${resource} -> ${quantity}`);
  18.   });
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement