Skip to content

Commit 422cebf

Browse files
committed
docs: clean-up documentation and examples and rename folder
Ref: #1384 Ref: 1ed81b7
1 parent e3eff9b commit 422cebf

File tree

8 files changed

+83
-43
lines changed

8 files changed

+83
-43
lines changed

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/README.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# countSameValueZero
2222

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.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -42,7 +42,7 @@ var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' );
4242

4343
#### countSameValueZero( x, value )
4444

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

4747
```javascript
4848
var x = [ 0, 1, 0, 1, 2 ];
@@ -51,6 +51,24 @@ var out = countSameValueZero( x, 1 );
5151
// returns 2
5252
```
5353

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+
5472
</section>
5573

5674
<!-- /.usage -->
@@ -72,10 +90,12 @@ var out = countSameValueZero( x, 1 );
7290
<!-- eslint no-undef: "error" -->
7391

7492
```javascript
75-
var sample = require( '@stdlib/random/sample' );
93+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
7694
var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' );
7795

78-
var x = sample( [ 1, 2, 3, 4, 5 ] );
96+
var x = bernoulli( 10, 0.5, {
97+
'dtype': 'generic'
98+
});
7999
console.log( x );
80100

81101
var n = countSameValueZero( x, 1 );
@@ -106,6 +126,8 @@ console.log( n );
106126

107127
<section class="links">
108128

129+
[@stdlib/array/base/count-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/count-same-value
130+
109131
</section>
110132

111133
<!-- /.links -->

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/repl.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
{{alias}}( x, value )
3-
Counts the number of elements that are equal to a given value in an array.
3+
Counts the number of elements in an array that are equal to a specified
4+
value.
5+
6+
The function treats `NaN` values as the same value.
47

58
Parameters
69
----------
@@ -13,7 +16,7 @@
1316
Returns
1417
-------
1518
out: integer
16-
Number of elements that are equal to the given value.
19+
Number of elements that are equal to a specified value.
1720

1821
Examples
1922
--------

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/docs/types/index.d.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
import { Collection } from '@stdlib/types/array';
2424

2525
/**
26-
* Counts the number of elements that are equal to a given value in an array.
26+
* Counts the number of elements in an array that are equal to a specified value.
27+
*
28+
* ## Notes
29+
*
30+
* - In contrast to an implementation based on the strict equality operator `===`, the function treats `NaNs` as the same value.
2731
*
2832
* @param x - input array
29-
* @param value - given value
30-
* @returns number of elements that are equal to the given value
33+
* @param value - search value
34+
* @returns number of elements that are equal to a specified value
3135
*
3236
* @example
3337
* var x = [ 0, 1, 0, 1, 1 ];

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/example/index.js renamed to lib/node_modules/@stdlib/array/base/count-same-value-zero/examples/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
'use strict';
2020

21-
var sample = require( '@stdlib/random/sample' );
21+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
2222
var countSameValueZero = require( './../lib' );
23-
var x;
24-
var n;
2523

26-
x = sample( [ 1, 2, 3, 4, 5 ] );
24+
var x = bernoulli( 10, 0.5, {
25+
'dtype': 'generic'
26+
});
2727
console.log( x );
2828

29-
n = countSameValueZero( x, 1 );
29+
var n = countSameValueZero( x, 1 );
3030
console.log( n );

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Count the number of elements that are equal to a given value in an array.
22+
* Count the number of elements in an array that are equal to a specified value.
2323
*
2424
* @module @stdlib/array/base/count-same-value-zero
2525
*

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/lib/main.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ var isSameValueZero = require( '@stdlib/assert/is-same-value-zero' );
3333
// FUNCTIONS //
3434

3535
/**
36-
* Counts the number of elements that are equal to a given value in an indexed array.
36+
* Counts the number of elements in an indexed array that are equal to a specified value.
3737
*
3838
* @private
3939
* @param {Collection} x - input array
40-
* @param {*} value - given value
41-
* @returns {NonNegativeInteger} number of elements that are equal to the given value
40+
* @param {*} value - search value
41+
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
4242
*
4343
* @example
4444
* var x = [ 0, 0, 1, 0, 1 ];
@@ -60,12 +60,12 @@ function indexed( x, value ) {
6060
}
6161

6262
/**
63-
* Counts the number of elements that are equal to a given value in an accessor array.
63+
* Counts the number of elements in an accessor array that are equal to a specified value.
6464
*
6565
* @private
6666
* @param {Collection} x - input array
67-
* @param {*} value - given value
68-
* @returns {NonNegativeInteger} number of elements that are equal to the given value
67+
* @param {*} value - search value
68+
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
6969
*
7070
* @example
7171
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
@@ -92,16 +92,16 @@ function accessors( x, value ) {
9292
}
9393

9494
/**
95-
* Counts the number of elements that are equal to a given value in a complex array.
95+
* Counts the number of elements in a complex array that are equal to a specified value.
9696
*
9797
* @private
9898
* @param {Collection} x - input array
99-
* @param {*} value - given value
100-
* @returns {NonNegativeInteger} number of elements that are equal to the given value
99+
* @param {*} value - search value
100+
* @returns {NonNegativeInteger} number of elements that are equal to a specified value
101101
*
102102
* @example
103-
* var Complex128 = require( '@stdlib/complex/float64' );
104103
* var Complex128Array = require( '@stdlib/array/complex128' );
104+
* var Complex128 = require( '@stdlib/complex/float64' );
105105
*
106106
* var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] );
107107
*
@@ -118,18 +118,14 @@ function complex( x, value ) {
118118
if ( !isComplexLike( value ) ) {
119119
return 0;
120120
}
121-
122121
re = real( value );
123122
im = imag( value );
124123

125124
view = reinterpret( x, 0 );
126125

127126
n = 0;
128127
for ( i = 0; i < view.length; i += 2 ) {
129-
if (
130-
isSameValueZero( view[ i ], re ) &&
131-
isSameValueZero( view[ i + 1 ], im )
132-
) {
128+
if ( isSameValueZero( view[ i ], re ) && isSameValueZero( view[ i+1 ], im ) ) { // eslint-disable-line max-len
133129
n += 1;
134130
}
135131
}
@@ -140,11 +136,16 @@ function complex( x, value ) {
140136
// MAIN //
141137

142138
/**
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.
144145
*
145146
* @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
148149
*
149150
* @example
150151
* var countSameValueZero = require( '@stdlib/array/base/count-same-value-zero' );

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/array/base/count-same-value-zero",
33
"version": "0.0.0",
4-
"description": "Count the number of elements that are equal to a given value in an array.",
4+
"description": "Count the number of elements in an array that are equal to a specified value.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",
@@ -17,6 +17,7 @@
1717
"directories": {
1818
"benchmark": "./benchmark",
1919
"doc": "./docs",
20+
"example": "./examples",
2021
"lib": "./lib",
2122
"test": "./test"
2223
},
@@ -59,6 +60,7 @@
5960
"summation",
6061
"countif",
6162
"total",
62-
"same"
63+
"same",
64+
"equal"
6365
]
6466
}

Diff for: lib/node_modules/@stdlib/array/base/count-same-value-zero/test/test.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ tape( 'the function counts the number of same values (generic)', function test(
4545
x = [ 0, 1, 0, 1, 2 ];
4646
expected = 2;
4747
actual = countSameValueZero( x, 1 );
48+
4849
t.strictEqual( actual, expected, 'returns expected value' );
4950
t.end();
5051
});
5152

52-
tape( 'the function consider positive and negative zeros to be indentical (generic)', function test( t ) {
53+
tape( 'the function considers positive and negative zeros to be identical (generic)', function test( t ) {
5354
var expected;
5455
var actual;
5556
var x;
@@ -67,7 +68,7 @@ tape( 'the function considers all NaN values to be identical (generic)', functio
6768
var actual;
6869
var x;
6970

70-
x = [ NaN, 0, NaN, 2, NaN, 9, NaN ];
71+
x = [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ];
7172
expected = 4;
7273
actual = countSameValueZero( x, NaN );
7374

@@ -87,7 +88,7 @@ tape( 'the function counts the number of same values (accessors)', function test
8788
t.end();
8889
});
8990

90-
tape( 'the function consider positive and negative zeros to be indentical (accessors)', function test( t ) {
91+
tape( 'the function considers positive and negative zeros to be identical (accessors)', function test( t ) {
9192
var expected;
9293
var actual;
9394
var x;
@@ -105,7 +106,7 @@ tape( 'the function considers all NaN values to be identical (accessors)', funct
105106
var actual;
106107
var x;
107108

108-
x = toAccessorArray( [ NaN, 0, NaN, 2, NaN, 9, NaN ] );
109+
x = toAccessorArray( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] );
109110
expected = 4;
110111
actual = countSameValueZero( x, NaN );
111112

@@ -126,7 +127,7 @@ tape( 'the function counts the number of same values (real typed array)', functi
126127
t.end();
127128
});
128129

129-
tape( 'the function consider positive and negative zeros to be indentical (real typed array)', function test( t ) {
130+
tape( 'the function considers positive and negative zeros to be identical (real typed array)', function test( t ) {
130131
var expected;
131132
var actual;
132133
var x;
@@ -144,7 +145,7 @@ tape( 'the function considers all NaN values to be identical (real typed array)'
144145
var actual;
145146
var x;
146147

147-
x = new Float32Array( [ NaN, 0, NaN, 2, NaN, 9, NaN ] );
148+
x = new Float32Array( [ NaN, 0.0, NaN, 2.0, NaN, 9.0, NaN ] );
148149
expected = 4;
149150
actual = countSameValueZero( x, NaN );
150151

@@ -160,16 +161,23 @@ tape( 'the function counts the number of same values (complex typed array)', fun
160161
x = new Complex128Array( [ 0.0, 0.0, 1.0, 0.0, 3.0, 4.0, 0.0, 5.0 ] );
161162
expected = 1;
162163
actual = countSameValueZero( x, new Complex128( 3.0, 4.0 ) );
164+
165+
t.strictEqual( actual, expected, 'returns expected value' );
166+
167+
x = new Complex128Array( [ 0.0, 0.0, 1.0, 0.0, 3.0, 4.0, 0.0, 5.0 ] );
168+
expected = 0;
169+
actual = countSameValueZero( x, 0.0 );
170+
163171
t.strictEqual( actual, expected, 'returns expected value' );
164172
t.end();
165173
});
166174

167-
tape( 'the function consider positive and negative zeros to be indentical (complex typed array)', function test( t ) {
175+
tape( 'the function considers positive and negative zeros to be identical (complex typed array)', function test( t ) {
168176
var expected;
169177
var actual;
170178
var x;
171179

172-
x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] );
180+
x = new Complex128Array( [ 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0 ] ); // eslint-disable-line max-len
173181
expected = 5;
174182
actual = countSameValueZero( x, new Complex128( 0.0, -0.0 ) );
175183

0 commit comments

Comments
 (0)