forked from busbud/coding-challenge-backend-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetCitiesFromString.js
44 lines (44 loc) · 892 Bytes
/
getCitiesFromString.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Returns the cities array from the tsv (string)
*
* @param {String} string
* @returns
*/
module.exports = function getCitiesFromString (string) {
return string
.split('\n')
.slice(1) // first line is the headers, so we drop it
.map(line => line.split('\t')) // tab is the delimiter of our string
.map(([
_geo_id,
name,
asciiname,
alternatenames,
latitude,
longitude,
_featureClass,
_fcode,
countryCode,
countryCode2,
adminCode1,
_adminCode2,
_adminCode3,
_adminCode4,
_population,
_elevation,
_dem,
_tz,
_modified_at
]) => ({
name,
asciiname,
alternatenames,
latitude,
longitude,
countryCode,
adminCode1
}))
.filter(city => // filter to valid our data
city.name && city.asciiname
)
}