translating
This commit is contained in:
parent
2b874a73be
commit
928cd2731b
165 changed files with 2046 additions and 2967 deletions
|
@ -0,0 +1,14 @@
|
|||
```js run
|
||||
function getAverageAge(users) {
|
||||
return arr.reduce((prev, user) => prev + user.age, 0) / arr.length;
|
||||
}
|
||||
|
||||
let john = { name: "John", age: 25 }
|
||||
let pete = { name: "Pete", age: 30 }
|
||||
let mary = { name: "Mary", age: 29 }
|
||||
|
||||
let arr = [ john, pete, mary ];
|
||||
|
||||
alert( getAverageAge(arr) ); // 28
|
||||
```
|
||||
|
22
1-js/4-data-structures/8-array-methods/8-average-age/task.md
Normal file
22
1-js/4-data-structures/8-array-methods/8-average-age/task.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
importance: 4
|
||||
|
||||
---
|
||||
|
||||
# Get average age
|
||||
|
||||
Write the function `getAverageAge(users)` that gets an array of objects with property `age` and gets the average.
|
||||
|
||||
The formula for the average is `(age1 + age2 + ... + ageN) / N`.
|
||||
|
||||
For instance:
|
||||
|
||||
```js no-beautify
|
||||
let john = { name: "John", age: 25 }
|
||||
let pete = { name: "Pete", age: 30 }
|
||||
let mary = { name: "Mary", age: 29 }
|
||||
|
||||
let arr = [ john, pete, mary ];
|
||||
|
||||
alert( getAverageAge(arr) ); // (25+30+29)/3 = 28
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue