-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
111 lines (94 loc) · 2.5 KB
/
utils.js
File metadata and controls
111 lines (94 loc) · 2.5 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { counties } = require("./getTownAndCounty.js");
const findCity = (sentence) => {
/**
* @summary This function finds the city in a sentence
* @param {String} sentence
* @param {Array} exclude
*
* @tutorial This function is used in the following sentences:
* - senteces: Regele Mihai a fost inmormantat la Curtea de Arges
* - result: Curtea de Arges
*
* @returns {String} city
*/
const allCities = counties
.map((county) => {
return Object.values(county).map((value) => {
return value.map((city) => {
return city.replace("-", " ");
});
});
})
.flat(2)
.sort();
const uniqueCities = [...new Set(allCities)];
// split sentence into words
const splitsSentence = sentence.split(" ");
// create an array of supposed cities
const supposedCity = [
...uniqueCities.filter((city) =>
splitsSentence
.map((word) => word.toLowerCase())
.includes(city.toLowerCase())
),
];
return [...new Set(supposedCity)];
};
const translate_city = (city) => {
/**
* @summary This function translates the city in romanian
* @param {String} city
*
* @returns {String} city
*/
city = city.replace(" ", "_");
// Populate this object with the cities that need translation
const cities = {
bucharest: "Bucuresti",
cluj: "Cluj-Napoca",
cluj_napoca: "Cluj-Napoca",
targu_mures: "Targu-Mures",
bucuresti_ilfov: "Bucuresti",
tg_mures: "Targu-Mures",
târgu_mureș: "Targu-Mures",
};
if (cities[city.toLowerCase()]) {
return cities[city.toLowerCase()];
} else {
return city.replace("_", " ");
}
};
const replace_char = (sentence, chars = [], charToReplace = "") => {
/**
* @summary This function replaces the characters in a sentence
* @param {String} sentence
* @param {Array} chars
* @param {String} charToReplace
*
* @returns {String} new sentence
*/
let new_sentence = sentence;
sentence.split("").forEach((char) => {
if (chars.includes(char)) {
new_sentence = new_sentence.replace(char, charToReplace);
}
});
return new_sentence;
};
const get_jobtype = (sentence) => {
/**
* @summary This function finds the job type in a sentence
* @param {String} sentence
*
* @returns {String} job type
*/
const job_types = ["remote", "hybrid"];
const jobType = job_types.filter((type) => sentence.includes(type));
return jobType;
};
module.exports = {
findCity,
translate_city,
replace_char,
get_jobtype,
};