@stdlib/array-base-count-same-value-zero
v0.2.0
Published
Count the number of elements in an array that are equal to a specified value.
Downloads
18
Readme
countSameValueZero
Count the number of elements in an array that are equal to a specified value.
Installation
npm install @stdlib/array-base-count-same-value-zero
Usage
var countSameValueZero = require( '@stdlib/array-base-count-same-value-zero' );
countSameValueZero( x, value )
Counts the number of elements in an array that are equal to a specified value.
var x = [ 0, 1, 0, 1, 2 ];
var out = countSameValueZero( x, 1 );
// returns 2
In contrast to an implementation using the strict equality operator ===
, the function treats NaNs
as the same value.
var x = [ NaN, NaN, NaN ];
var out = countSameValueZero( x, NaN );
// returns 3
In contrast to an implementation using the SameValue Algorithm (as specified in ECMAScript 5), the function does not distinguish between +0
and -0
.
var x = [ 0.0, -0.0, 0.0 ];
var out = countSameValueZero( x, 0.0 );
// returns 3
Examples
var bernoulli = require( '@stdlib/random-array-bernoulli' );
var countSameValueZero = require( '@stdlib/array-base-count-same-value-zero' );
var x = bernoulli( 10, 0.5, {
'dtype': 'generic'
});
console.log( x );
var n = countSameValueZero( x, 1 );
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.