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
45 lines (35 loc) · 1022 Bytes
/
Copy pathobjects.js
File metadata and controls
45 lines (35 loc) · 1022 Bytes
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
const createPerson = (name, age) => {
return {
name: name,
age: age
};
};
const getName = object => object.name;
const getProperty = (property, object) => object[property];
const hasProperty = (property, object) => object.hasOwnProperty(property);
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 => Math.round(people.reduce((total, person) => total + ((person.age/people.length)), 0));
const createTalkingPerson = (name, age) => {
return {
name: name,
age: age,
introduce: function(pal) {
return `Hi ${pal}, my name is ${this.name} and I am ${this.age}!`
}
}
};
module.exports = {
createPerson,
getName,
getProperty,
hasProperty,
isOver65,
getAges,
findByName,
findHondas,
averageAge,
createTalkingPerson
};