Skip to content

Instantly share code, notes, and snippets.

@johnathanDOS
Created April 26, 2017 04:22
Show Gist options
  • Save johnathanDOS/8806e9c322c58d9ce7b32ac18b12156b to your computer and use it in GitHub Desktop.
Save johnathanDOS/8806e9c322c58d9ce7b32ac18b12156b to your computer and use it in GitHub Desktop.
/*eloquent javascript solution*/
var differences = ancestry.filter(function(person) {
return byName[person.mother] != null;
}).map(function(person) {
return person.born - byName[person.mother].born;
});
console.log(average(differences))
/* my solution */
var ageDifferences = [];
ancestry.forEach(function(person) {
if (byName[person.mother] != null) {
ageDifferences.push(person.born - byName[person.mother].born)
}
})
console.log(average(ageDifferences))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment