percent-of ( ... seq quot: ( ... elt -- ... ? ) -- ... % )


Vocabulary
sequences.extras

Inputs
seqa sequence
quota quotation with stack effect ( ... elt -- ... ? )


Outputs
%a rational


Word description
Outputs the fraction of elements in the sequence for which the predicate quotation matches.

Examples
USING: math ranges prettyprint sequences.extras ; 100 [1..b] [ even? ] percent-of .
1/2


Definition


: percent-of ( ... seq quot: ( ... elt -- ... ? ) -- ... % )
over length 0 =
[ 2drop 0 ] [ over [ count ] [ length ] bi* / ] if ; inline