-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing-map.js
More file actions
46 lines (42 loc) · 1002 Bytes
/
using-map.js
File metadata and controls
46 lines (42 loc) · 1002 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function citiesOnly(ar) {
return ar.map((x) => x.city)
}
function upperCasingStates(ar) {
return ar.map((x) => capitalize(x))
}
function capitalize(s) {
s=s.split(" ")
for (let i=0;i<s.length;i++){
s[i]=s[i].charAt(0).toUpperCase() + s[i].slice(1);
}
return s.join(' ')
}
function fahrenheitToCelsius(ar) {
return ar.map((x) => convert(x.slice(0, x.length - 2)) + "°C")
}
function convert(f) {
return Math.floor((f - 32) * 5 / 9);
}
function trimTemp(obj) {
return obj.map((o) => {
o.temperature = trim(o.temperature)
return o
})
}
function trim(s) {
let ss = ''
s = s.split('')
for (let i = 0; i < s.length; i++) {
if (s[i] != ' ') {
ss = ss + s[i]
}
}
return ss
}
function tempForecasts(obj) {
return obj.map((o) => {
let t=trim(o.temperature)
t=convert(t.slice(0,t.length-2))
return t+'°Celsius in '+capitalize(o.city)+', '+capitalize(o.state)
})
}