Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function towns(input) {
- let headings = input.shift().split(' ').filter(a => !a.includes('|')); //[ 'Town', 'Latitude', 'Longitude' ]
- let output = [];
- for (let i = 0; i < input.length; i++) {
- let current = input[i].split(' ').filter(a => !a.includes('|'));
- let result = {};
- result[headings[0]] = current[0];
- result[headings[1]] = Number(current[1]);
- result[headings[2]] = Number(current[2]);
- output.push(result);
- result = {};
- }
- output = '[' + output
- .map(x => x = `{"Town":"${x.Town}","Latitude":${x.Latitude.toFixed(2)},"Longitude":${x.Longitude.toFixed(2)}}`)
- .join(',') + ']';
- console.log(output);
- }
Advertisement
Add Comment
Please, Sign In to add comment