Advertisement
kstoyanov

01. Towns to JSON

Sep 20th, 2020 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   const inputArr = arr.slice(1);
  3.   const towns = [];
  4.   const regex = /\s*\|\s*/;
  5.  
  6.   inputArr.forEach((el) => {
  7.     const arrTown = el.split(regex).filter(Boolean);
  8.  
  9.     const longi = Number(arrTown[2]).toFixed(2);
  10.     const lati = Number(arrTown[1]).toFixed(2);
  11.  
  12.  
  13.     const townObj = { Town: arrTown[0], Latitude: Number(lati), Longitude: Number(longi) };
  14.     towns.push(townObj);
  15.   });
  16.  
  17.  
  18.   console.log(JSON.stringify(towns));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement