Skip to content

Instantly share code, notes, and snippets.

@TimBlock
Created January 15, 2016 11:00
Show Gist options
  • Save TimBlock/0055f5e818e793706e7c to your computer and use it in GitHub Desktop.
Save TimBlock/0055f5e818e793706e7c to your computer and use it in GitHub Desktop.
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 dif = ancestry.filter(function(person) {
return byName[person.mother];}).map(function(person) {
return person.born - byName[person.mother].born;
});
console.log(average(dif));
// Your code here.
// → 31.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment