forked from CommandShiftHQ/javascript-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
67 lines (57 loc) · 1.22 KB
/
Copy pathobjects.js
File metadata and controls
67 lines (57 loc) · 1.22 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
const createPerson = (name, age) => {
const person = {
name: name,
age: age
}
return person;
};
const getName = object => {
return object.name;
};
const getProperty = (property, object) => {
return object[property];
};
const hasProperty = (property, object) => {
// eslint-disable-next-line no-prototype-builtins
return object.hasOwnProperty(property);
};
const isOver65 = person => {
return person.age > 65;
};
const getAges = people => {
return people.map(person => {
return person.age;
})
};
const findByName = (name, people) => {
return people.find(person => person.name === name);
};
const findHondas = cars => {
return cars.filter(car => car.manufacturer === 'Honda');
};
const averageAge = people => {
const totalAge = people.reduce((total, person) => total + person.age, 0);
return totalAge / people.length;
};
const createTalkingPerson = (name, age) => {
const person = {
name,
age,
introduce(name) {
return `Hi ${name}, my name is ${this.name} and I am ${this.age}!`;
}
};
return person;
};
module.exports = {
createPerson,
getName,
getProperty,
hasProperty,
isOver65,
getAges,
findByName,
findHondas,
averageAge,
createTalkingPerson
};