Skip to content

Commit 41e36bc

Browse files
committed
Allow typed arrays of arbitrary length
1 parent 360f59b commit 41e36bc

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/node_modules/@stdlib/random/sample/lib/factory.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2424
var isArrayLike = require( '@stdlib/assert/is-array-like' );
25+
var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
2526
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2627
var randu = require( '@stdlib/random/base/mt19937' ).factory;
2728
var copy = require( '@stdlib/utils/copy' );
@@ -43,7 +44,7 @@ var slice = Array.prototype.slice;
4344
/**
4445
* Returns a function to sample elements from an array-like object.
4546
*
46-
* @param {ArrayLike} [pool] - array-like object from which to sample
47+
* @param {(ArrayLike|TypedArrayLike)} [pool] - array-like object from which to sample
4748
* @param {Options} [options] - function options
4849
* @param {PositiveInteger} [options.seed] - integer-valued seed
4950
* @param {NonNegativeInteger} [options.size] - sample size
@@ -144,7 +145,7 @@ function factory() {
144145

145146
conf = copy( defaults );
146147
if ( arguments.length === 1 ) {
147-
if ( isArrayLike( arguments[ 0 ] ) ) {
148+
if ( isArrayLike( arguments[ 0 ] ) || isTypedArrayLike( arguments[ 0 ] ) ) { // eslint-disable-line max-len
148149
pool = arguments[ 0 ];
149150
} else {
150151
config = arguments[ 0 ];
@@ -153,7 +154,7 @@ function factory() {
153154
} else if ( arguments.length > 1 ) {
154155
pool = arguments[ 0 ];
155156
config = arguments[ 1 ];
156-
if ( !isArrayLike( pool ) ) {
157+
if ( !( isArrayLike( pool ) || isTypedArrayLike( pool ) ) ) {
157158
throw new TypeError( 'invalid argument. `pool` argument must be array-like. Value: `' + pool + '`.' );
158159
}
159160
err = validate( conf, config );
@@ -189,7 +190,7 @@ function factory() {
189190
* Samples elements from an array-like object.
190191
*
191192
* @private
192-
* @param {ArrayLike} x - array-like object from which to sample elements
193+
* @param {(ArrayLike|TypedArrayLike)} x - array-like object from which to sample elements
193194
* @param {Options} [options] - function options
194195
* @param {NonNegativeInteger} [options.size] - sample size
195196
* @param {ProbabilityArray} [options.probs] - element probabilities
@@ -208,7 +209,7 @@ function factory() {
208209
var size;
209210
var err;
210211

211-
if ( !isArrayLike( x ) ) {
212+
if ( !( isArrayLike( x ) || isTypedArrayLike( x ) ) ) {
212213
throw new TypeError( 'invalid argument. First argument must be array-like. Value: `' + x + '`.' );
213214
}
214215
if ( isString( x ) ) {

lib/node_modules/@stdlib/random/shuffle/lib/factory.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2424
var isArrayLike = require( '@stdlib/assert/is-array-like' );
25+
var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
2526
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2627
var deepCopy = require( '@stdlib/utils/copy' );
2728
var floor = require( '@stdlib/math/base/special/floor' );
@@ -79,7 +80,7 @@ function factory( config ) {
7980
* Returns a random permutation of elements in `arr`.
8081
*
8182
* @private
82-
* @param {ArrayLike} arr - array-like object to shuffle
83+
* @param {(ArrayLike|TypedArrayLike)} arr - array-like object to shuffle
8384
* @param {Options} [options] - function options
8485
* @param {string} [options.copy] - string indicating whether to return a copy (`deep`,`shallow` or `none`)
8586
* @throws {TypeError} first argument must be array-like
@@ -112,7 +113,7 @@ function factory( config ) {
112113
var i;
113114
var j;
114115

115-
if ( !isArrayLike( arr ) ) {
116+
if ( !( isArrayLike( arr ) || isTypedArrayLike( arr ) ) ) {
116117
throw new TypeError( 'invalid argument. First argument must be array-like. Value: `' + arr + '`.' );
117118
}
118119
if ( arguments.length > 1 ) {

0 commit comments

Comments
 (0)