22
22
23
23
var setReadOnly = require ( '@stdlib/utils/define-nonenumerable-read-only-property' ) ;
24
24
var isArrayLike = require ( '@stdlib/assert/is-array-like' ) ;
25
+ var isTypedArrayLike = require ( '@stdlib/assert/is-typed-array-like' ) ;
25
26
var isString = require ( '@stdlib/assert/is-string' ) . isPrimitive ;
26
27
var randu = require ( '@stdlib/random/base/mt19937' ) . factory ;
27
28
var copy = require ( '@stdlib/utils/copy' ) ;
@@ -43,7 +44,7 @@ var slice = Array.prototype.slice;
43
44
/**
44
45
* Returns a function to sample elements from an array-like object.
45
46
*
46
- * @param {ArrayLike } [pool] - array-like object from which to sample
47
+ * @param {( ArrayLike|TypedArrayLike) } [pool] - array-like object from which to sample
47
48
* @param {Options } [options] - function options
48
49
* @param {PositiveInteger } [options.seed] - integer-valued seed
49
50
* @param {NonNegativeInteger } [options.size] - sample size
@@ -144,7 +145,7 @@ function factory() {
144
145
145
146
conf = copy ( defaults ) ;
146
147
if ( arguments . length === 1 ) {
147
- if ( isArrayLike ( arguments [ 0 ] ) ) {
148
+ if ( isArrayLike ( arguments [ 0 ] ) || isTypedArrayLike ( arguments [ 0 ] ) ) { // eslint-disable-line max-len
148
149
pool = arguments [ 0 ] ;
149
150
} else {
150
151
config = arguments [ 0 ] ;
@@ -153,7 +154,7 @@ function factory() {
153
154
} else if ( arguments . length > 1 ) {
154
155
pool = arguments [ 0 ] ;
155
156
config = arguments [ 1 ] ;
156
- if ( ! isArrayLike ( pool ) ) {
157
+ if ( ! ( isArrayLike ( pool ) || isTypedArrayLike ( pool ) ) ) {
157
158
throw new TypeError ( 'invalid argument. `pool` argument must be array-like. Value: `' + pool + '`.' ) ;
158
159
}
159
160
err = validate ( conf , config ) ;
@@ -189,7 +190,7 @@ function factory() {
189
190
* Samples elements from an array-like object.
190
191
*
191
192
* @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
193
194
* @param {Options } [options] - function options
194
195
* @param {NonNegativeInteger } [options.size] - sample size
195
196
* @param {ProbabilityArray } [options.probs] - element probabilities
@@ -208,7 +209,7 @@ function factory() {
208
209
var size ;
209
210
var err ;
210
211
211
- if ( ! isArrayLike ( x ) ) {
212
+ if ( ! ( isArrayLike ( x ) || isTypedArrayLike ( x ) ) ) {
212
213
throw new TypeError ( 'invalid argument. First argument must be array-like. Value: `' + x + '`.' ) ;
213
214
}
214
215
if ( isString ( x ) ) {
0 commit comments