Created
April 26, 2017 04:22
-
-
Save johnathanDOS/8806e9c322c58d9ce7b32ac18b12156b to your computer and use it in GitHub Desktop.
This file contains 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
/*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