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
84 lines (59 loc) · 1.76 KB
/
app.js
File metadata and controls
84 lines (59 loc) · 1.76 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
console.log("Hello World!\n==========\n");
// Exercise 1 Section
console.log("EXERCISE 1:\n==========\n");
function plus (num) {
return function (plusNumber) {
return num + plusNumber;
}
};
const plus15 = plus(15); // this syntax allows for endless const of number pairings that can be passed through the function
console.log(plus15(10)) // = 25
// Exercise 2 Section
console.log("EXERCISE 2:\n==========\n");
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,
},
];
users.forEach(users => console.log (users.name)) // lists just the names of the users within the array
// Exercise 3 Section
console.log("EXERCISE 3:\n==========\n");
let newArr = users.map((user) => { // creating new array with just names and scores of each user
return {name: user.name, score: user.score};
})
console.log(newArr)
// Exercise 4 Section
console.log("EXERCISE 4:\n==========\n");
let actStatus = users.filter((users) => // creating new array based on isActive = true within users
users.isActive)
console.log(actStatus);
// Exercise 5 Section
console.log("EXERCISE 5:\n==========\n");
users.sort ((a, b) => b.score - a.score); // b.score > a.score returns 1/swaps the order; 0 or negative, don't swap
console.log(users);
// Exercise 6 Section
console.log("EXERCISE 6:\n==========\n");
let average = users.reduce ((sum, user) =>
sum + user.score, 0) / users.length; // used to find the sum and average of number values in an array
console.log(average)