countTruthy
Count the number of truthy elements in an array.
Usage
var countTruthy = require( '@stdlib/array/base/count-truthy' );
countTruthy( x )
Counts the number of truthy elements in an array.
var x = [ 0, 1, 0, 1, 2 ];
var out = countTruthy( x );
// returns 3
Examples
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var countTruthy = require( '@stdlib/array/base/count-truthy' );
var x = bernoulli( 100, 0.5, {
'dtype': 'generic'
});
console.log( x );
var n = countTruthy( x );
console.log( n );