Skip to content

Instantly share code, notes, and snippets.

@oliverjam
Created November 8, 2016 19:32
Show Gist options
  • Save oliverjam/dbb8519c3a770ba70109a4d9efefb8a2 to your computer and use it in GitHub Desktop.
Save oliverjam/dbb8519c3a770ba70109a4d9efefb8a2 to your computer and use it in GitHub Desktop.
EJ: C5 P2 created by oliverjam - https://repl.it/ES00/2
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;
});
function avgAgeDiff(data) {
return data.filter(entry => byName[entry.mother] !== null && byName[entry.mother] !== undefined)
.map(entry => entry.born - byName[entry.mother].born);
}
console.log(average(avgAgeDiff(ancestry)));
// Get an array of age differences (map?)
// Filter out null answers
// Average the array
// → 31.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment