728x90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAverageAge(students) { | |
return students.reduce((acc, student) => acc + student.age, 0) / students.length; | |
} | |
let john = { name: "John", age: 25 }; | |
let pete = { name: "Pete", age: 30 }; | |
let mary = { name: "Mary", age: 29 }; | |
let arr = [ john, pete, mary ]; | |
console.log( getAverageAge(arr) ); // (25 + 30 + 29) / 3 = 28 |
'Algorithm > JavaScript(Node.js)' 카테고리의 다른 글
The Modern JS Tutorial: array-methods: Create keyed object from array (0) | 2021.09.23 |
---|---|
The Modern JS Tutorial: array-methods: filter unique array members (0) | 2021.09.22 |
The Modern JS Tutorial: array-methods: shuffle an array (0) | 2021.09.21 |
The Modern JS Tutorial: array-methods: sort users by age (0) | 2021.09.20 |
The Modern JS Tutorial: array-methods: map to objects (0) | 2021.09.20 |