Jump to content

Functional coverage tree: Difference between revisions

m
→‎{{header|JavaScript}}: Minor reordering of functions, for legibility.
m ((Moved JS to a more plausible position in the lexicographic sequence))
m (→‎{{header|JavaScript}}: Minor reordering of functions, for legibility.)
Line 710:
 
// TWO TRAVERSAL COMPUTATIONS
 
withResidueShares(1.0)(
foldTree(weightedCoverage)(
Line 737 ⟶ 738:
 
// COVERAGE AND SHARES OF RESIDUE ---------------------
 
// weightedCoverage :: Dict -> Forest Dict -> Tree Dict
const weightedCoverage = x => xs => {
const
cws = map(compose(
fanArrow(x => x.coverage)(x => x.weight),
root
))(xs),
totalWeight = cws.reduce((a, tpl) => a + snd(tpl), 0);
return Node(
insertDict('coverage')(
cws.reduce((a, tpl) => {
const [c, w] = Array.from(tpl);
return a + (c * w);
}, x.coverage) / (
0 < totalWeight ? totalWeight : 1
)
)(x)
)(xs);
};
 
 
// withResidueShares :: Float -> Tree Dict -> Tree Dict
Line 759 ⟶ 781:
};
 
// weightedCoverage :: Dict -> Forest Dict -> Tree Dict
const weightedCoverage = x => xs => {
const
cws = map(compose(
fanArrow(x => x.coverage)(x => x.weight),
root
))(xs),
totalWeight = cws.reduce((a, tpl) => a + snd(tpl), 0);
return Node(
insertDict('coverage')(
cws.reduce((a, tpl) => {
const [c, w] = Array.from(tpl);
return a + (c * w);
}, x.coverage) / (
0 < totalWeight ? totalWeight : 1
)
)(x)
)(xs);
};
 
// OUTLINE PARSED TO TREE -----------------------------
Line 1,175 ⟶ 1,178:
wine_cellar | 1 | 1.0000 | 0.0000
cinema | 1 | 0.7500 | 0.0167 </pre>
 
 
=={{header|Julia}}==
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.