-
Notifications
You must be signed in to change notification settings - Fork 10
/
awardAgeCalculator.js
50 lines (47 loc) · 1.11 KB
/
awardAgeCalculator.js
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
var awardAgeCalculator = (function() {
"use strict";
var getPeople = function() {
return [{
name: "Herta Muller",
birthYear: 1953,
awardYear: 2009
}, {
name: "Mario Vargas Llosa",
birthYear: 1936,
awardYear: 2010
}, {
name: "Tomas Transtromer",
birthYear: 1931,
awardYear: 2011
}, {
name: "Mo Yan",
birthYear: 1955,
awardYear: 2012
}, {
name: "Alice Munro",
birthYear: 1931,
awardYear: 2013
}, {
name: "Patrick Modiano",
birthYear: 1945,
awardYear: 2014
}];
};
var getPeopleWithAwardAge = function() {
return _.map(getPeople(), function(person) {
return {
name: person.name,
awardAge: person.awardYear - person.birthYear
};
});
};
return {
getPeopleWithAwardAge: getPeopleWithAwardAge,
getAverageAwardAge: function() {
var peopleWithAwardAge = getPeopleWithAwardAge();
return _.reduce(peopleWithAwardAge, function(memo, person) {
return memo + person.awardAge;
}, 0) / peopleWithAwardAge.length;
}
};
}());