You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/array/base/count-same-value-zero/README.md
+26-4
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ limitations under the License.
20
20
21
21
# countSameValueZero
22
22
23
-
> Count the number of elements that are equal to a given value in an array.
23
+
> Count the number of elements in an array that are equal to a specified value.
24
24
25
25
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26
26
@@ -42,7 +42,7 @@ var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' );
42
42
43
43
#### countSameValueZero( x, value )
44
44
45
-
Counts the number of elements that are equal to a given value in an array.
45
+
Counts the number of elements in an array that are equal to a specified value.
46
46
47
47
```javascript
48
48
var x = [ 0, 1, 0, 1, 2 ];
@@ -51,6 +51,24 @@ var out = countSameValueZero( x, 1 );
51
51
// returns 2
52
52
```
53
53
54
+
In contrast to an implementation using the strict equality operator `===`, the function distinguishes treats `NaNs` as the same value.
55
+
56
+
```javascript
57
+
var x = [ NaN, NaN, NaN ];
58
+
59
+
var out =countSameValueZero( x, NaN );
60
+
// returns 3
61
+
```
62
+
63
+
In contrast to an implementation using the [SameValue Algorithm][@stdlib/array/base/count-same-value] (as specified in ECMAScript 5), the function does not distinguish between `+0` and `-0`.
64
+
65
+
```javascript
66
+
var x = [ 0.0, -0.0, 0.0 ];
67
+
68
+
var out =countSameValueZero( x, 0.0 );
69
+
// returns 3
70
+
```
71
+
54
72
</section>
55
73
56
74
<!-- /.usage -->
@@ -72,10 +90,12 @@ var out = countSameValueZero( x, 1 );
@@ -140,11 +136,16 @@ function complex( x, value ) {
140
136
// MAIN //
141
137
142
138
/**
143
-
* Counts the number of elements that are equal to a given value in an array.
139
+
* Counts the number of elements in an array that are equal to a specified value.
140
+
*
141
+
* ## Notes
142
+
*
143
+
* - The function uses the SameValueZero Algorithm used by `TypedArray` and `ArrayBuffer` constructors, `Map` and `Set` operations, `String.prototype.includes`, and `Array.prototype.includes` since ES2016.
144
+
* - In contrast to an implementation based on the strict equality operator `===`, the function treats `NaNs` as the same value.
144
145
*
145
146
* @param {Collection} x - input array
146
-
* @param {*} value - given value
147
-
* @returns {NonNegativeInteger} number of elements that are equal to the given value
147
+
* @param {*} value - search value
148
+
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
148
149
*
149
150
* @example
150
151
* var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' );
0 commit comments