-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapExercises.js
117 lines (107 loc) · 2.15 KB
/
mapExercises.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
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
112
113
114
115
116
117
function doubleNumbers(arr) {
return arr.map(item => item * 2);
}
console.log(doubleNumbers([2, 5, 100])); // [4, 10, 200]
function stringItUp(arr) {
return arr.map(item => item.toString());
}
console.log(stringItUp([2, 5, 100])); // ["2", "5", "100"]
function capitalizeNames(arr) {
return arr.map(word => word.toUpperCase());
}
console.log(capitalizeNames(["john", "JACOB", "jinGleHeimer", "schmidt"])); // ["John", "Jacob", "Jingleheimer", "Schmidt"]
function namesOnly(arr) {
return arr.map(word => word.name);
}
console.log(
namesOnly([
{
name: "Angelina Jolie",
age: 80
},
{
name: "Eric Jones",
age: 2
},
{
name: "Paris Hilton",
age: 5
},
{
name: "Kayne West",
age: 16
},
{
name: "Bob Ziroll",
age: 100
}
])
);
// ["Angelina Jolie", "Eric Jones", "Paris Hilton", "Kayne West", "Bob Ziroll"]
function makeStrings(arr) {
return arr.map(person => {
if (person.age > 18) return `${person.name} can go to The Matrix`;
return `${person.name} is under age`;
});
}
console.log(
makeStrings([
{
name: "Angelina Jolie",
age: 80
},
{
name: "Eric Jones",
age: 2
},
{
name: "Paris Hilton",
age: 5
},
{
name: "Kayne West",
age: 16
},
{
name: "Bob Ziroll",
age: 100
}
])
);
// ["Angelina Jolie can go to The Matrix",
// "Eric Jones is under age!!",
// "Paris Hilton is under age!!",
// "Kayne West is under age!!",
// "Bob Ziroll can go to The Matrix"]
function readyToPutInTheDOM(arr) {
return arr.map(person => `<h1>${person.name}</h1><h2>${person.age}</h2>`);
}
console.log(
readyToPutInTheDOM([
{
name: "Angelina Jolie",
age: 80
},
{
name: "Eric Jones",
age: 2
},
{
name: "Paris Hilton",
age: 5
},
{
name: "Kayne West",
age: 16
},
{
name: "Bob Ziroll",
age: 100
}
])
);
// ["<h1>Angelina Jolie</h1><h2>80</h2>",
// "<h1>Eric Jones</h1><h2>2</h2>",
// "<h1>Paris Hilton</h1><h2>5</h2>",
// "<h1>Kayne West</h1><h2>16</h2>",
// "<h1>Bob Ziroll</h1><h2>100</h2>"]