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
62 lines (52 loc) · 1.11 KB
/
Copy pathobjects.js
File metadata and controls
62 lines (52 loc) · 1.11 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
const createPerson = (name, age) => {
return { name, age };
};
const getName = object => {
return object.name;
};
const getProperty = (property, object) => {
return object[property];
};
const hasProperty = (property, object) => {
return object.hasOwnProperty(property);
};
const isOver65 = person => {
return person.age > 65;
};
const getAges = people => {
const newArr = [];
for (let i = 0; i < people.length; i++) {
newArr.push(people[i].age);
}
return newArr;
};
const findByName = (name, people) => {
return people.find(people => people.name === name);
};
const findHondas = cars => {
return cars.filter(cars => cars.manufacturer === 'Honda')
};
const averageAge = people => {
return people.reduce((a, b) => a + b.age, 0) / people.length;
};
const createTalkingPerson = (name, age) => {
return {
name,
age,
introduce: introduce => {
return `Hi ${introduce}, my name is ${name} and I am ${age}!`;
}
}
};
module.exports = {
createPerson,
getName,
getProperty,
hasProperty,
isOver65,
getAges,
findByName,
findHondas,
averageAge,
createTalkingPerson
};