nikolayneykov

Untitled

Mar 4th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function towns(input) {
  2.     let headings = input.shift().split(' ').filter(a => !a.includes('|')); //[ 'Town', 'Latitude', 'Longitude' ]
  3.     let output = [];
  4.  
  5.     for (let i = 0; i < input.length; i++) {
  6.         let current = input[i].split(' ').filter(a => !a.includes('|'));
  7.         let result = {};
  8.         result[headings[0]] = current[0];
  9.         result[headings[1]] = Number(current[1]);
  10.         result[headings[2]] = Number(current[2]);
  11.         output.push(result);
  12.         result = {};
  13.     }
  14.  
  15.     output = '[' + output
  16.         .map(x => x = `{"Town":"${x.Town}","Latitude":${x.Latitude.toFixed(2)},"Longitude":${x.Longitude.toFixed(2)}}`)
  17.         .join(',') + ']';
  18.     console.log(output);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment