forked from truecodersio/JavaScript_HOF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
109 lines (69 loc) · 1.85 KB
/
app.js
File metadata and controls
109 lines (69 loc) · 1.85 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
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
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
function plus(number) {
return function (plusNumber) {
return plusNumber + number;
};
}
let plus15 = plus(15);
//Using a function within a function. Allows you to see a variable with a parameter
//already inserted.
console.log(plus15(10));
// Exercise 2 Section
let users = [
{
name: "Frodo",
age: 50,
score: 85,
isActive: false,
},
{
name: "Sam",
age: 38,
score: 94,
isActive: true,
},
{
name: "Merry",
age: 36,
score: 82,
isActive: true,
},
{
name: "Pippin",
age: 26,
score: 77,
isActive: false,
},
];
console.log("EXERCISE 2:\n==========\n");
users.forEach(function (param) {
console.log(param.name);
});
//Loops through the array and logs each name.
// Exercise 3 Section
console.log("EXERCISE 3:\n==========\n");
let userScore = users.map(function (user) {
return { name: user.name, score: user.score };
});
console.log(userScore)
//Places this new object initialization onto every object in the array
//in order to create new objects with the desired info.
// Exercise 4 Section
console.log("EXERCISE 4:\n==========\n");
let active = users.filter(active => active.isActive !== false)
//Goes through and checks which values meet the condition.
console.log(active)
// Exercise 5 Section
console.log("EXERCISE 5:\n==========\n");
let sorted = users.sort((a,b) => b.score - a.score);
//Passes through and subtracts the scores from each other. + or - determines
//order.
console.log(sorted)
// Exercise 6 Section
console.log("EXERCISE 6:\n==========\n");
let avgScore = users.reduce((sum, user) => sum + user.score, 0) / users.length;
//Passes through array, adding, starting from 0.
//Devide by length because that's the # of users.
console.log(avgScore)