Advertisement
kstoyanov

02. Sum by Town

Sep 20th, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   const towns = {};
  3.  
  4.   arr.forEach((el, index) => {
  5.     if (index % 2 === 0) {
  6.       if (!Object.prototype.hasOwnProperty.call(towns, el)) {
  7.         towns[el] = 0;
  8.       }
  9.       towns[el] += Number(arr[index + 1]);
  10.     }
  11.   });
  12.  
  13.   console.log(JSON.stringify(towns));
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement