Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. function average(array) {
  2. function plus(a, b) { return a + b; }
  3. return array.reduce(plus) / array.length;
  4. }
  5.  
  6. var byName = {};
  7. ancestry.forEach(function(person) {
  8. byName[person.name] = person;
  9. });
  10.  
  11. var hasMotherAncestry = ancestry.filter(function(person) {
  12. if(byName[person.mother] != null)
  13. return person;
  14. });
  15.  
  16. var arrayMomsAgeAtBirth = hasMotherAncestry.map(function(iterator) {
  17. return iterator.born - byName[iterator.mother].born
  18. });
  19.  
  20. console.log(average(arrayMomsAgeAtBirth));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement