Created
November 8, 2016 19:32
-
-
Save oliverjam/dbb8519c3a770ba70109a4d9efefb8a2 to your computer and use it in GitHub Desktop.
EJ: C5 P2 created by oliverjam - https://repl.it/ES00/2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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