-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (25 loc) · 947 Bytes
/
index.js
File metadata and controls
28 lines (25 loc) · 947 Bytes
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
//if can use require
const cities = require("./cities.json");//if can require
const citiesNames = cities.map(item => item.name);
exports.citiesNames = citiesNames;
exports.cities = cities;
exports.filterByCityName = ( query , limit = 3) => {
if(query && query.length >= limit){
return citiesNames.filter(item => {
let result = item.toLowerCase().search( query.toLowerCase()) >= 0
return result;
})
}else
return [];
}
exports.filterByName= ( query , limit = 3) => {
if(query && query.length >= limit){
return cities.filter(item => {
let result = item.name.toLowerCase().search( query.toLowerCase()) >= 0
result = result || item.subcountry.toLowerCase().search( query.toLowerCase() ) >= 0
result = result || item.country.toLowerCase().search( query.toLowerCase()) >= 0
return result;
})
}else
return [];
}