Skip to content

Commit 261c095

Browse files
committed
fix: examples
1 parent 17ada8c commit 261c095

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

lib/node_modules/@stdlib/stats/array/range/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The function has the following parameters:
6060
## Notes
6161

6262
- If provided an empty array, the function returns `NaN`.
63+
- The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).
6364

6465
</section>
6566

@@ -102,6 +103,8 @@ console.log( v );
102103

103104
[range]: https://en.wikipedia.org/wiki/Range_%28statistics%29
104105

106+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
107+
105108
</section>
106109

107110
<!-- /.links -->

lib/node_modules/@stdlib/stats/array/range/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { NumericArray, Collection } from '@stdlib/types/array';
23+
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
2424

2525
/**
2626
* Input array.
2727
*/
28-
type InputArray = NumericArray | Collection<number>;
28+
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
2929

3030
/**
3131
* Computes the range of an array.

lib/node_modules/@stdlib/stats/array/range/docs/types/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
import AccessorArray = require( '@stdlib/array/base/accessor' );
1920
import range = require( './index' );
2021

2122

@@ -26,6 +27,7 @@ import range = require( './index' );
2627
const x = new Float64Array( 10 );
2728

2829
range( x ); // $ExpectType number
30+
range( new AccessorArray( x ) ); // $ExpectType number
2931
}
3032

3133
// The compiler throws an error if the function is provided a first argument which is not a numeric array...

lib/node_modules/@stdlib/stats/array/range/test/test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
2526
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
2627
var BooleanArray = require( '@stdlib/array/bool' );
2728
var Complex128Array = require( '@stdlib/array/complex128' );
@@ -115,6 +116,33 @@ tape( 'the function calculates the range of an array', function test( t ) {
115116
t.end();
116117
});
117118

119+
tape( 'the function calculates the range of an array (accessors)', function test( t ) {
120+
var x;
121+
var v;
122+
123+
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
124+
v = range( toAccessorArray( x ) );
125+
t.strictEqual( v, 9.0, 'returns expected value' );
126+
127+
x = [ -4.0, -5.0 ];
128+
v = range( toAccessorArray( x ) );
129+
t.strictEqual( v, 1.0, 'returns expected value' );
130+
131+
x = [ -0.0, 0.0, -0.0 ];
132+
v = range( toAccessorArray( x ) );
133+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
134+
135+
x = [ NaN ];
136+
v = range( toAccessorArray( x ) );
137+
t.strictEqual( isnan( v ), true, 'returns expected value' );
138+
139+
x = [ NaN, NaN ];
140+
v = range( toAccessorArray( x ) );
141+
t.strictEqual( isnan( v ), true, 'returns expected value' );
142+
143+
t.end();
144+
});
145+
118146
tape( 'the function calculates the range of an array (array-like object)', function test( t ) {
119147
var x;
120148
var v;
@@ -140,8 +168,20 @@ tape( 'if provided an empty array, the function returns `NaN`', function test( t
140168
t.end();
141169
});
142170

171+
tape( 'if provided an empty array, the function returns `NaN` (accessors)', function test( t ) {
172+
var v = range( toAccessorArray( [] ) );
173+
t.strictEqual( isnan( v ), true, 'returns expected value' );
174+
t.end();
175+
});
176+
143177
tape( 'if provided an array containing a single element, the function returns `0`', function test( t ) {
144178
var v = range( [ 1.0 ] );
145179
t.strictEqual( v, 0.0, 'returns expected value' );
146180
t.end();
147181
});
182+
183+
tape( 'if provided an array containing a single element, the function returns `0` (accessors)', function test( t ) {
184+
var v = range( toAccessorArray( [ 1.0 ] ) );
185+
t.strictEqual( v, 0.0, 'returns expected value' );
186+
t.end();
187+
});

0 commit comments

Comments
 (0)