1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Gets the numeric total of adding all the values in a list together.
// Values that are false, null, or undefined are skipped over.
import {input, templateCompositeFrom} from '#composite';
import {isNumber, sparseArrayOf} from '#validators';
export default templateCompositeFrom({
annotation: `withSum`,
inputs: {
values: input({
validate: sparseArrayOf(isNumber),
}),
},
outputs: ['#sum'],
steps: () => [
{
dependencies: [input('values')],
compute: (continuation, {
[input('values')]: values,
}) => continuation({
['#sum']:
values
.filter(item => typeof item === 'number')
.reduce(
(accumulator, value) => accumulator + value,
0),
}),
},
],
});
|