-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathreduce.js
52 lines (39 loc) · 1.09 KB
/
reduce.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
import { students } from "./data/sample_data.js";
// let total = 0;
// for (let i = 0; i < points.length; i++) {
// total += points[i];
// }
// const total = points.reduce((total, point) => {
// return total + point;
// }, 0);
const total = points.reduce((total, point) => total + point, 0);
const totalAges = students.reduce((total, student) => total + student.age, 0);
totalAges;
const developers = [
{
id: 1,
name: "John",
skills: ["HTML", "React", "Javascript", "Java"],
},
{
id: 2,
name: "Jane",
skills: ["HTML", "CSS", "JavaScript", "React", "Redux", "NodeJS"],
},
{
id: 3,
name: "Jack",
skills: ["HTML", "CSS", "JavaScript", "React", "Redux", "NodeJS"],
},
];
const result = developers.reduce(function (allSkills, student) {
return Array.from(new Set([...allSkills, ...student.skills]));
}, []);
console.log(result);
// let total = 0
// for (let i = 0; i < students.length; i++) {
// total += students[i].age
// }
// console.log(total)
// const result = students.reduce((total, student) => total + student.age, 0)
// console.log(result)