-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathobjects.js
More file actions
50 lines (40 loc) · 1.02 KB
/
objects.js
File metadata and controls
50 lines (40 loc) · 1.02 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
const createPerson = (name, age) => {
return {
name,
age
};
};
const getName = object => object.name;
const getProperty = (property, object) => object[property];
const hasProperty = (property, object) => property in object;
const isOver65 = person => person.age > 65;
const getAges = people => people.map(person => person.age);
const findByName = (name, people) =>
people.filter(person => person.name === name)[0];
const findHondas = cars => cars.filter(car => car.manufacturer === "Honda");
const averageAge = people => {
const ages = people.map(person => person.age);
const average = ages.reduce((a, b) => a + b);
return average / ages.length;
};
const createTalkingPerson = (name, age) => {
const person = {
name,
age,
introduce: personname =>
`Hi ${personname}, my name is ${name} and I am ${age}!`
};
return person;
};
module.exports = {
createPerson,
getName,
getProperty,
hasProperty,
isOver65,
getAges,
findByName,
findHondas,
averageAge,
createTalkingPerson
};