Skip to content

Commit 821035c

Browse files
committed
refactor: only check properties when options has been provided
1 parent 4c956ca commit 821035c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

lib/node_modules/@stdlib/blas/ext/index-of/lib/assign.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ function assign( x, searchElement, fromIndex, out ) {
188188
options = arguments[ 4 ];
189189
hasOptions = true;
190190
}
191-
if ( hasOptions && !isPlainObject( options ) ) {
192-
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
193-
}
194-
// Resolve provided options...
195-
if ( hasOwnProp( options, 'dim' ) ) {
196-
opts.dims[ 0 ] = options.dim;
191+
if ( hasOptions ) {
192+
if ( !isPlainObject( options ) ) {
193+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
194+
}
195+
// Resolve provided options...
196+
if ( hasOwnProp( options, 'dim' ) ) {
197+
opts.dims[ 0 ] = options.dim;
198+
}
197199
}
198200
// Resolve the list of non-reduced dimensions:
199201
sh = getShape( x );

lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,20 @@ function indexOf( x, searchElement, fromIndex ) {
161161
options = arguments[ 3 ];
162162
hasOptions = true;
163163
}
164-
if ( hasOptions && !isPlainObject( options ) ) {
165-
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
166-
}
167-
// Resolve provided options...
168-
if ( hasOwnProp( options, 'dim' ) ) {
169-
opts.dims[ 0 ] = options.dim;
170-
}
171-
if ( hasOwnProp( options, 'keepdims' ) ) {
172-
opts.keepdims = options.keepdims;
173-
}
174-
if ( hasOwnProp( options, 'dtype' ) ) {
175-
opts.dtype = options.dtype;
164+
if ( hasOptions ) {
165+
if ( !isPlainObject( options ) ) {
166+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
167+
}
168+
// Resolve provided options...
169+
if ( hasOwnProp( options, 'dim' ) ) {
170+
opts.dims[ 0 ] = options.dim;
171+
}
172+
if ( hasOwnProp( options, 'keepdims' ) ) {
173+
opts.keepdims = options.keepdims;
174+
}
175+
if ( hasOwnProp( options, 'dtype' ) ) {
176+
opts.dtype = options.dtype;
177+
}
176178
}
177179
// Resolve the list of non-reduced dimensions:
178180
sh = getShape( x );

0 commit comments

Comments
 (0)