-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcities.js
54 lines (41 loc) · 1.4 KB
/
cities.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
45
46
47
48
49
50
51
52
53
54
const fileInput = document.getElementById('cities-file')
let citiesRate = []
/////////////function 1///////////////////
const mainReturn = (fileInput.onchange = () => {
const reader = new FileReader()
reader.readAsText(fileInput.files[0])
reader.addEventListener('load', (event) => {
const result = event.target.result
console.log(result)
citiesRate = result //comment for formatting
.split(/\r\n/)
.filter((a) => /[1-9]/.test(a))
.map((c, i) => ({
city: c.split(',').slice(2, 3)[0],
place: i + 1,
population: c.split(',').slice(-1)[0],
}))
.sort((a, b) => (b.population || 0) - (a.population || 0))
.slice(0, 10)
console.log(citiesRate)
})
const textarea = document.querySelector('.cities-textarea')
//////////function 2//////////////////
let text = ''
document.querySelector('.button-get-cities').addEventListener('click', () => {
console.log('getCities')
text = textarea.value
console.log(text)
citiesRate.forEach((city) => {
if (text.includes(city.city)) {
text = text.replaceAll(
city.city,
`${city.city} (${city.place} місце в ТОП-10 самих великих міст України, населення ${city.population} чоловік)`
)
}
})
console.log(text)
document.querySelector('.text').innerHTML = text
return text
})
})