@@ -628,14 +628,24 @@ Groups the elements of an array by the result of the [predicate](#predicate).
628628groupBy(users, .Age)
629629```
630630
631- ### count(array, predicate) {#count}
631+ ### count(array[ , predicate] ) {#count}
632632
633633Returns the number of elements what satisfies the [ predicate] ( #predicate ) .
634634
635+ ``` expr
636+ count(users, .Age > 18)
637+ ```
638+
635639Equivalent to:
636640
637641``` expr
638- len(filter(array, predicate))
642+ len(filter(users, .Age > 18))
643+ ```
644+
645+ If the predicate is not given, returns the number of ` true ` elements in the array.
646+
647+ ``` expr
648+ count([true, false, true]) == 2
639649```
640650
641651### concat(array1, array2[ , ...] ) {#concat}
@@ -673,14 +683,29 @@ reduce(1..9, #acc + #)
673683reduce(1..9, #acc + #, 0)
674684```
675685
676- ### sum(array) {#sum}
686+ ### sum(array[ , predicate ] ) {#sum}
677687
678688Returns the sum of all numbers in the array.
679689
680690``` expr
681691sum([1, 2, 3]) == 6
682692```
683693
694+ If the optional ` predicate ` argument is given, it is a predicate that is applied on each element
695+ of the array before summing.
696+
697+ ``` expr
698+ sum(accounts, .Balance)
699+ ```
700+
701+ Equivalent to:
702+
703+ ``` expr
704+ reduce(accounts, #acc + .Balance, 0)
705+ // or
706+ sum(map(accounts, .Balance))
707+ ```
708+
684709### mean(array) {#mean}
685710
686711Returns the average of all numbers in the array.
0 commit comments