-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusing-map.js
44 lines (40 loc) · 1.04 KB
/
using-map.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
function citiesOnly(arr) {
return arr.map((item) => item.city);
}
function upperCasingStates(arr) {
return arr.map((item) =>
item
.split(" ")
.map((word) => {
return word[0].toUpperCase() + word.slice(1);
})
.join(" ")
);
}
function fahrenheitToCelsius(arr) {
return arr.map(
(item) =>
Math.floor((Number(item.slice(0, -2)) - 32) * (5 / 9)).toString() +
"°C"
);
}
function trimTemp(arr) {
return arr.map((item) => {
item.temperature = item.temperature.replaceAll(" ", "");
return item;
});
}
function tempForecasts(arr) {
return arr.map((item) => {
return `${
Math.floor(
(Number(item.temperature.slice(0, -2)) - 32) * (5 / 9)
).toString() + "°Celsius"
} in ${item.city}, ${item.state
.split(" ")
.map((word) => {
return word[0].toUpperCase() + word.slice(1);
})
.join(" ")}`;
});
}