@@ -816,18 +816,18 @@ machine that is me that originates with Pauwels.
816816function)))(((abstraction)))We could also have computed this number
817817without relying on `reduceAncestors`. But separating the general
818818approach (condensing a family tree) from the specific case (computing
819- shared DNA) can improve the clarity of the code and allows us to
820- reuse the abstract part of the program for other cases. For example,
821- the following code finds the percentage of known ancestors, for a
822- given person, who lived past 70 :
819+ shared DNA) can improve the clarity of the code and allows us to reuse
820+ the abstract part of the program for other cases. For example, the
821+ following code finds the percentage of a person's known ancestors who
822+ lived past 70 (by lineage, so people may be counted multiple times) :
823823
824824// test: clip
825825
826826[source,javascript]
827827----
828828function countAncestors(person, test) {
829- function combine(person , fromMother, fromFather) {
830- var thisOneCounts = test(person );
829+ function combine(current , fromMother, fromFather) {
830+ var thisOneCounts = current != person && test(current );
831831 return fromMother + fromFather + (thisOneCounts ? 1 : 0);
832832 }
833833 return reduceAncestors(person, combine, 0);
@@ -842,7 +842,7 @@ function longLivingPercentage(person) {
842842 return longLiving / all;
843843}
844844console.log(longLivingPercentage(byName["Emile Haverbeke"]));
845- // → 0.145
845+ // → 0.129
846846----
847847
848848Such numbers are not to be taken too seriously, given that
0 commit comments