Advertisement
bebo231312312321

Untitled

Feb 2nd, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function townsToJSON(input) {
  2.  
  3.     const inputL = input.length;
  4.     const townInfo = [];
  5.  
  6.     for (let i = 1; i < inputL; i++) {
  7.         let [town, latitude, longitude] = input[i]
  8.             .split('|')
  9.             .filter(x => x.length > 0)
  10.             .map(x => x.trim());
  11.         townInfo.push({
  12.             Town: town,
  13.             Latitude: Number(Number(latitude).toFixed(2)),
  14.             Longitude: Number(Number(longitude).toFixed(2)),
  15.         });
  16.     }
  17.     const result = JSON.stringify(townInfo);
  18.     console.log(result);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement