Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function average(array) {
- function plus(a, b) { return a + b; }
- return array.reduce(plus) / array.length;
- }
- var byName = {};
- ancestry.forEach(function(person) {
- byName[person.name] = person;
- });
- var hasMotherAncestry = ancestry.filter(function(person) {
- if(byName[person.mother] != null)
- return person;
- });
- var arrayMomsAgeAtBirth = hasMotherAncestry.map(function(iterator) {
- return iterator.born - byName[iterator.mother].born
- });
- console.log(average(arrayMomsAgeAtBirth));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement