mirozspace

towns

Sep 11th, 2020
823
23 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function townsToJSON(input) {
  2.     let towns = [];
  3.     let regex = /\s*\|\s*/;
  4.  
  5.     for(let line of input.splice(1)) {
  6.         let tokens = line.split(regex);
  7.         let townObj = { Town: tokens[1], Latitude: Number(tokens[2]).toFixed(2), Longitude: Number(tokens[3]).toFixed(2)};
  8.         townObj.Latitude = +(townObj.Latitude);
  9.         townObj.Longitude = Number(townObj.Longitude);
  10.         towns.push(townObj);
  11.     }
  12.     console.log(JSON.stringify(towns));
  13. }
RAW Paste Data