# @stdlib/array-base-count-same-value-zero

0.2.0 • Public • Published

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

# 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.

## Package Sidebar

### Install

`npm i @stdlib/array-base-count-same-value-zero`

stdlib.io

12

0.2.0

Apache-2.0

37.9 kB

11