Advertisement
Liliana797979

towns to JSON - js advanced

Sep 23rd, 2021
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function towns(array = []) {
  2.   class Town {
  3.     constructor(name, latitude, longitude) {
  4.       this.name = name;
  5.       this.latitude = latitude;
  6.       this.longitude = longitude;
  7.     }
  8.   }
  9.   for (let i = 0; i < array.length; i++) {
  10.     let arr = array[i].split(" | ");
  11.     let name = arr[0];
  12.     let latitude = +arr[1];
  13.     let longitude = +arr[2];
  14.     town = new Town(name, latitude, longitude);
  15.     console.log(
  16.       `{ town: '${town.name}', latitude: '${latitude.toFixed(
  17.        2
  18.      )}', longitude: '${longitude.toFixed(2)}' }`
  19.     );
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement