@stdlib/array-base-count-truthy
v0.2.0
Published
Count the number of truthy elements in an array.
Downloads
330
Readme
countTruthy
Count the number of truthy elements in an array.
Installation
npm install @stdlib/array-base-count-truthy
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 );
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.