-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 1002 Bytes
/
index.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
const fs = require('fs');
const decancer = require('decancer')
const airportCodes = JSON.parse(fs.readFileSync('./data/airportCodes.json', 'utf-8'));
/**
* @param {string} String to extract airport codes from.
* @description Returns the airport codes for the cities in the string. If not, it returns.
*/
function getAirportCode(string) {
let words = string.split(" ");
let matchingCodes = [];
for (var i = 0; i < airportCodes.length; i++) {
let cityWords = airportCodes[i].city.split(" ");
let match = true;
for (var j = 0; j < cityWords.length; j++) {
if (!decancer(string.toLowerCase()).toString().includes(decancer(cityWords[j].toLowerCase()).toString())) {
match = false;
break;
}
}
if (match) {
matchingCodes.push(airportCodes[i].code);
}
}
if (matchingCodes.length > 0) {
return matchingCodes;
}
}
module.exports = {
getAirportCode
}