-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing-map.js
More file actions
70 lines (66 loc) · 2.13 KB
/
Copy pathusing-map.js
File metadata and controls
70 lines (66 loc) · 2.13 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
function citiesOnly(states) {
let array = states.map(cites => {
return cites.city
})
return array
}
function upperCasingStates(cities) {
let array = cities.map(function city(currentValue) {
const regex = /^\w/g
const regexSpace = /\s\w/g
const regexSp = new RegExp(regexSpace)
const regexSt = new RegExp(regex)
let res1 = currentValue.match(regexSt)
let res2 = currentValue.match(regexSp)
let res = currentValue.replace(regexSt, res1[0].toUpperCase())
if (res2 !== null) {
res = res.replace(regexSp, res2[0].toUpperCase())
}
return res
})
return array
}
function fahrenheitToCelsius(temperature) {
let array = temperature.map(function Celsia(value) {
value = parseInt(value)
let cel = (value - 32) * 5 / 9
cel = Math.floor(cel)
return cel + '°C'
})
return array
}
function trimTemp(states) {
let array = states.map(temp => {
const regex = /\s/g
const resRegex = new RegExp(regex)
let strin = temp.temperature
let str = strin.match(resRegex)
let res = strin.replace(resRegex, '')
temp.temperature = res
return temp
})
return array
}
function tempForecasts(states) {
let array = states.map(all => {
const regex = /\s/g
const resRegex = new RegExp(regex)
const regexSpace = /\s\w/g
const regexSp = new RegExp(regexSpace)
let strin = all.temperature
let res2 = all.state.match(regexSp)
let str = strin.match(resRegex)
// let res3 = all.state.match(regexSp)
let res = strin.replace(resRegex, '')
if (res2 !== null) {
all.state = all.state.replace(regexSp, res2[0].toUpperCase())
}
res = parseInt(res)
let cel = (res - 32) * 5 / 9
cel = Math.floor(cel)
let strRes = cel + '°Celsius in ' + all.city + ', ' + all.state[0].toUpperCase() + all.state.slice(1)
return strRes
})
return array
}
// console.log(tempForecasts(states))