22
22
23
23
var hasOwnProp = require ( '@stdlib/assert/has-own-property' ) ;
24
24
var objectAssign = require ( '@stdlib/object/assign' ) ;
25
+ var isObject = require ( '@stdlib/assert/is-object' ) ;
25
26
var isInteger = require ( '@stdlib/assert/is-integer' ) . isPrimitive ;
26
27
var isndarrayLike = require ( '@stdlib/assert/is-ndarray-like' ) ;
27
28
var broadcastScalar = require ( '@stdlib/ndarray/base/broadcast-scalar' ) ;
@@ -96,15 +97,15 @@ function indexOf( x, searchElement, fromIndex, options ) {
96
97
var dt ;
97
98
var sh ;
98
99
100
+ if ( ! isndarrayLike ( x ) ) {
101
+ throw new TypeError ( format ( 'invalid argument. The first argument must be an ndarray-like object. Value: `%s`.' , x ) ) ;
102
+ }
103
+
99
104
nargs = arguments . length ;
100
105
if ( nargs < 2 ) {
101
106
throw new TypeError ( format ( 'invalid argument. The function must be provided at least two arguments. Value: `%s`.' , nargs ) ) ;
102
107
}
103
108
104
- if ( ! isndarrayLike ( x ) ) {
105
- throw new TypeError ( format ( 'invalid argument. The first argument must be an ndarray-like object. Value: `%s`.' , x ) ) ;
106
- }
107
-
108
109
// Resolve input ndarray meta data:
109
110
dt = getDType ( x ) ;
110
111
ord = getOrder ( x ) ;
@@ -120,13 +121,16 @@ function indexOf( x, searchElement, fromIndex, options ) {
120
121
else if (
121
122
nargs === 3 &&
122
123
! isndarrayLike ( fromIndex ) &&
123
- ! isInteger ( fromIndex )
124
+ isObject ( fromIndex )
124
125
) {
125
126
opts = objectAssign ( opts , fromIndex ) ;
126
127
fromIndex = 0 ;
127
128
}
128
129
// Case: indexOf( x, searchElement, fromIndex, options )
129
130
else if ( nargs === 4 ) {
131
+ if ( ! isObject ( options ) ) {
132
+ throw new TypeError ( format ( 'invalid argument. The fourth argument must be an object. Value: `%s`.' , options ) ) ;
133
+ }
130
134
opts = objectAssign ( opts , options ) ;
131
135
}
132
136
0 commit comments