Skip to content

Commit 63b911a

Browse files
authored
refactor: reduce duplicated logic
Signed-off-by: Athan <kgryte@gmail.com>
1 parent 3732bab commit 63b911a

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

  • lib/node_modules/@stdlib/blas/ext/join-between/lib

lib/node_modules/@stdlib/blas/ext/join-between/lib/main.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ function joinBetween( x, separators, options ) {
8080
var opts;
8181
var sep;
8282
var shx;
83-
var sh;
83+
var shc;
84+
var flg;
8485
var M;
8586
var p;
8687
var s;
@@ -118,50 +119,46 @@ function joinBetween( x, separators, options ) {
118119
}
119120
shx = getShape( x );
120121

122+
// Resolve the complement shape...
123+
if hasOwnProp( opts, 'dims' ) ) {
124+
shc = nonCoreShape( shx, opts.dims );
125+
flg = true;
126+
} else {
127+
shc = [];
128+
flg = false;
129+
}
121130
// Broadcast prefix to the complement shape...
122131
if ( isndarrayLike( p ) ) {
123-
if ( hasOwnProp( opts, 'dims' ) ) {
124-
prefix = maybeBroadcastArray( p, nonCoreShape( shx, opts.dims ) );
132+
if ( flg ) {
133+
prefix = maybeBroadcastArray( p, shc );
125134
} else if ( ndims( p ) === 0 ) {
126135
prefix = p;
127136
} else {
128137
throw new TypeError( format( 'invalid option. `%s` option must be a zero-dimensional ndarray when not specifying dimensions. Value: `%s`.', 'prefix', p ) );
129138
}
130139
} else {
131-
if ( hasOwnProp( opts, 'dims' ) ) {
132-
sh = nonCoreShape( shx, opts.dims );
133-
} else {
134-
sh = [];
135-
}
136-
prefix = broadcastScalar( p, 'generic', sh, getOrder( x ) );
140+
prefix = broadcastScalar( p, 'generic', shc, getOrder( x ) );
137141
}
138142
// Broadcast suffix to the complement shape...
139143
if ( isndarrayLike( s ) ) {
140-
if ( hasOwnProp( opts, 'dims' ) ) {
141-
suffix = maybeBroadcastArray( s, nonCoreShape( shx, opts.dims ) );
144+
if ( flg ) {
145+
suffix = maybeBroadcastArray( s, shc );
142146
} else if ( ndims( s ) === 0 ) {
143147
suffix = s;
144148
} else {
145149
throw new TypeError( format( 'invalid option. `%s` option must be a zero-dimensional ndarray when not specifying dimensions. Value: `%s`.', 'suffix', s ) );
146150
}
147151
} else {
148-
if ( hasOwnProp( opts, 'dims' ) ) {
149-
sh = nonCoreShape( shx, opts.dims );
150-
} else {
151-
sh = [];
152-
}
153-
suffix = broadcastScalar( s, 'generic', sh, getOrder( x ) );
152+
suffix = broadcastScalar( s, 'generic', shc, getOrder( x ) );
154153
}
155154
// Broadcast separators to [ ...complementShape, M-1 ] where M is the number of elements along the reduced dimensions...
156-
if ( hasOwnProp( opts, 'dims' ) ) {
157-
sh = nonCoreShape( shx, opts.dims );
158-
M = numel( shx ) / numel( sh );
155+
if ( flg ) {
156+
M = numel( shx ) / numel( shc );
159157
} else {
160-
sh = [];
161158
M = numel( shx );
162159
}
163-
sh.push( M - 1 );
164-
sep = maybeBroadcastArray( separators, sh );
160+
shc.push( M - 1 );
161+
sep = maybeBroadcastArray( separators, shc );
165162

166163
return base( x, prefix, suffix, sep, opts );
167164
}

0 commit comments

Comments
 (0)