Skip to content

Commit 02aa25b

Browse files
committed
refactor: apply suggestions from code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 211d572 commit 02aa25b

File tree

7 files changed

+104
-87
lines changed

7 files changed

+104
-87
lines changed

lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface Routine {
4646
* var str = gjoin( x.length, ',', x, 1 );
4747
* // returns '1,2,3,4'
4848
*/
49-
( N: number, separator: unknown, x: InputArray, strideX: number ): string;
49+
( N: number, separator: string, x: InputArray, strideX: number ): string;
5050

5151
/**
5252
* Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics.
@@ -64,7 +64,7 @@ interface Routine {
6464
* var str = gjoin.ndarray( x.length, ',', x, 1, 0 );
6565
* // returns '1,2,3,4'
6666
*/
67-
ndarray( N: number, separator: unknown, x: InputArray, strideX: number, offsetX: number ): string;
67+
ndarray( N: number, separator: string, x: InputArray, strideX: number, offsetX: number ): string;
6868
}
6969

7070
/**

lib/node_modules/@stdlib/blas/ext/base/gjoin/docs/types/test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ import gjoin = require( './index' );
4242
gjoin( ( x: number ): number => x, ',', x, 1 ); // $ExpectError
4343
}
4444

45+
// The compiler throws an error if the function is provided a second argument which is not a string...
46+
{
47+
const x = [ 1, 2, 3, 4 ];
48+
49+
gjoin( x.length, 5, x, 1 ); // $ExpectError
50+
gjoin( x.length, true, x, 1 ); // $ExpectError
51+
gjoin( x.length, false, x, 1 ); // $ExpectError
52+
gjoin( x.length, null, x, 1 ); // $ExpectError
53+
gjoin( x.length, undefined, x, 1 ); // $ExpectError
54+
gjoin( x.length, [], x, 1 ); // $ExpectError
55+
gjoin( x.length, {}, x, 1 ); // $ExpectError
56+
gjoin( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError
57+
}
58+
4559
// The compiler throws an error if the function is provided a third argument which is not an array-like object...
4660
{
4761
gjoin( 4, ',', 5, 1 ); // $ExpectError
@@ -97,6 +111,20 @@ import gjoin = require( './index' );
97111
gjoin.ndarray( ( x: number ): number => x, ',', x, 1, 0 ); // $ExpectError
98112
}
99113

114+
// The compiler throws an error if the `ndarray` method is provided a second argument which is not a string...
115+
{
116+
const x = [ 1, 2, 3, 4 ];
117+
118+
gjoin.ndarray( x.length, 5, x, 1, 0 ); // $ExpectError
119+
gjoin.ndarray( x.length, true, x, 1, 0 ); // $ExpectError
120+
gjoin.ndarray( x.length, false, x, 1, 0 ); // $ExpectError
121+
gjoin.ndarray( x.length, null, x, 1, 0 ); // $ExpectError
122+
gjoin.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError
123+
gjoin.ndarray( x.length, [], x, 1, 0 ); // $ExpectError
124+
gjoin.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError
125+
gjoin.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError
126+
}
127+
100128
// The compiler throws an error if the `ndarray` method is provided a third argument which is not an array-like object...
101129
{
102130
gjoin.ndarray( 4, ',', 5, 1, 0 ); // $ExpectError

lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/accessors.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@
1818

1919
'use strict';
2020

21-
// MODULES //
22-
23-
var join = require( '@stdlib/array/base/join' );
24-
25-
2621
// MAIN //
2722

2823
/**
2924
* Returns a string created by joining strided array elements using a specified separator.
3025
*
3126
* @private
3227
* @param {PositiveInteger} N - number of indexed elements
33-
* @param {*} separator - separator
28+
* @param {string} separator - separator
3429
* @param {Object} x - input array object
3530
* @param {Collection} x.data - input array data
3631
* @param {Array<Function>} x.accessors - array element accessors
@@ -44,31 +39,50 @@ var join = require( '@stdlib/array/base/join' );
4439
*
4540
* var x = [ 1, 2, 3, 4 ];
4641
*
47-
* var str = gjoin( x.length, ',', arraylike2object( toAccessorArray( x ) ), 1, 0 );
42+
* var out = gjoin( x.length, ',', arraylike2object( toAccessorArray( x ) ), 1, 0 );
4843
* // returns '1,2,3,4'
4944
*/
5045
function gjoin( N, separator, x, strideX, offsetX ) {
5146
var xbuf;
52-
var view;
5347
var get;
48+
var out;
5449
var ix;
50+
var v;
5551
var i;
5652

53+
if ( N <= 0 ) {
54+
return '';
55+
}
56+
5757
// Cache reference to array data:
5858
xbuf = x.data;
5959

6060
// Cache a reference to the element accessor:
6161
get = x.accessors[ 0 ];
6262

63-
// Create a view of the strided elements
64-
view = [];
63+
if ( N === 1 ) {
64+
// Get the single element:
65+
v = get( xbuf, offsetX );
66+
if ( v === null || v === void 0 ) {
67+
return '';
68+
}
69+
return String( v );
70+
}
71+
72+
out = '';
6573
ix = offsetX;
6674
for ( i = 0; i < N; i++ ) {
67-
view.push( get( xbuf, ix ) );
75+
if ( i > 0 ) {
76+
out += separator;
77+
}
78+
v = get( xbuf, ix );
79+
if ( v !== null && v !== void 0 ) {
80+
out += String( v );
81+
}
6882
ix += strideX;
6983
}
7084

71-
return join( view, separator );
85+
return out;
7286
}
7387

7488

lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ var ndarray = require( './ndarray.js' );
3030
* Returns a string created by joining strided array elements using a specified separator.
3131
*
3232
* @param {PositiveInteger} N - number of indexed elements
33-
* @param {*} separator - separator
33+
* @param {string} separator - separator
3434
* @param {Collection} x - input array
3535
* @param {integer} strideX - stride length
3636
* @returns {string} joined string
3737
*
3838
* @example
3939
* var x = [ 1, 2, 3, 4 ];
4040
*
41-
* var str = gjoin( x.length, ',', x, 1 );
42-
* // returns '1,2,3,4'
41+
* var out = gjoin( x.length, ',', x, 1 );
42+
* // return '1,2,3,4'
4343
*/
4444
function gjoin( N, separator, x, strideX ) {
4545
return ndarray( N, separator, x, strideX, stride2offset( N, strideX ) );

lib/node_modules/@stdlib/blas/ext/base/gjoin/lib/ndarray.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
24-
var join = require( '@stdlib/array/base/join' );
2524
var accessors = require( './accessors.js' );
2625

2726

@@ -31,7 +30,7 @@ var accessors = require( './accessors.js' );
3130
* Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics.
3231
*
3332
* @param {PositiveInteger} N - number of indexed elements
34-
* @param {*} separator - separator
33+
* @param {string} separator - separator
3534
* @param {Collection} x - input array
3635
* @param {integer} strideX - stride length
3736
* @param {NonNegativeInteger} offsetX - starting index
@@ -40,13 +39,14 @@ var accessors = require( './accessors.js' );
4039
* @example
4140
* var x = [ 1, 2, 3, 4 ];
4241
*
43-
* var str = gjoin( x.length, ',', x, 1, 0 );
42+
* var out = gjoin( x.length, ',', x, 1, 0 );
4443
* // returns '1,2,3,4'
4544
*/
4645
function gjoin( N, separator, x, strideX, offsetX ) {
47-
var view;
46+
var out;
4847
var ix;
4948
var o;
49+
var v;
5050
var i;
5151

5252
if ( N <= 0 ) {
@@ -57,15 +57,30 @@ function gjoin( N, separator, x, strideX, offsetX ) {
5757
return accessors( N, separator, o, strideX, offsetX );
5858
}
5959

60-
// Create a view of the strided elements
61-
view = [];
60+
if ( N === 1 ) {
61+
// Get the single element:
62+
v = x[ offsetX ];
63+
if ( v === null || v === void 0 ) {
64+
return '';
65+
}
66+
return String( v );
67+
}
68+
69+
// Build the string directly without creating intermediate array:
70+
out = '';
6271
ix = offsetX;
6372
for ( i = 0; i < N; i++ ) {
64-
view.push( x[ ix ] );
73+
if ( i > 0 ) {
74+
out += separator;
75+
}
76+
v = x[ ix ];
77+
if ( v !== null && v !== void 0 ) {
78+
out += String( v );
79+
}
6580
ix += strideX;
6681
}
6782

68-
return join( view, separator );
83+
return out;
6984
}
7085

7186

lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.main.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ tape( 'the function returns a string created by joining strided array elements',
6161
actual = gjoin( 3, '-', x, -2 );
6262
t.strictEqual( actual, '5-3-1', 'returns expected value' );
6363

64+
// Null and undefined values...
65+
x = [ 1, null, 3, undefined, 5 ];
66+
actual = gjoin( x.length, ',', x, 1 );
67+
t.strictEqual( actual, '1,,3,,5', 'returns expected value' );
68+
6469
t.end();
6570
});
6671

@@ -87,10 +92,15 @@ tape( 'the function returns a string created by joining strided array elements (
8792
actual = gjoin( 3, '-', x, -2 );
8893
t.strictEqual( actual, '5-3-1', 'returns expected value' );
8994

95+
// Null and undefined values...
96+
x = toAccessorArray( [ 1, null, 3, undefined, 5 ] );
97+
actual = gjoin( x.length, ',', x, 1 );
98+
t.strictEqual( actual, '1,,3,,5', 'returns expected value' );
99+
90100
t.end();
91101
});
92102

93-
tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero', function test( t ) {
103+
tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero', function test( t ) {
94104
var actual;
95105

96106
actual = gjoin( 0, ',', [ 1.0, 2.0, 3.0 ], 1 );
@@ -102,7 +112,7 @@ tape( 'the function returns an empty string if provided `N` parameter is less th
102112
t.end();
103113
});
104114

105-
tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero (accessors)', function test( t ) {
115+
tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero (accessors)', function test( t ) {
106116
var actual;
107117

108118
actual = gjoin( 0, ',', toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 );
@@ -113,33 +123,3 @@ tape( 'the function returns an empty string if provided `N` parameter is less th
113123

114124
t.end();
115125
});
116-
117-
tape( 'the function handles null and undefined values', function test( t ) {
118-
var actual;
119-
var x;
120-
121-
x = [ 1, null, 3, undefined, 5 ];
122-
123-
actual = gjoin( x.length, ',', x, 1 );
124-
t.strictEqual( actual, '1,,3,,5', 'returns expected value' );
125-
126-
t.end();
127-
});
128-
129-
tape( 'the function handles different separator types', function test( t ) {
130-
var actual;
131-
var x;
132-
133-
x = [ 1, 2, 3 ];
134-
135-
actual = gjoin( x.length, '', x, 1 );
136-
t.strictEqual( actual, '123', 'returns expected value' );
137-
138-
actual = gjoin( x.length, ' - ', x, 1 );
139-
t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' );
140-
141-
actual = gjoin( x.length, 0, x, 1 );
142-
t.strictEqual( actual, '10203', 'returns expected value' );
143-
144-
t.end();
145-
});

lib/node_modules/@stdlib/blas/ext/base/gjoin/test/test.ndarray.js

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ tape( 'the function returns a string created by joining strided array elements',
6767
actual = gjoin( 3, '|', x, -2, x.length-2 );
6868
t.strictEqual( actual, '5|3|1', 'returns expected value' );
6969

70+
// Null and undefined values...
71+
x = [ 1, null, 3, undefined, 5 ];
72+
actual = gjoin( x.length, ',', x, 1, 0 );
73+
t.strictEqual( actual, '1,,3,,5', 'returns expected value' );
74+
7075
t.end();
7176
});
7277

@@ -99,6 +104,11 @@ tape( 'the function returns a string created by joining strided array elements (
99104
actual = gjoin( 3, '|', x, -2, x.length-2 );
100105
t.strictEqual( actual, '5|3|1', 'returns expected value' );
101106

107+
// Null and undefined values...
108+
x = toAccessorArray( [ 1, null, 3, undefined, 5 ] );
109+
actual = gjoin( x.length, ',', x, 1, 0 );
110+
t.strictEqual( actual, '1,,3,,5', 'returns expected value' );
111+
102112
t.end();
103113
});
104114

@@ -125,33 +135,3 @@ tape( 'the function returns an empty string if provided an `N` parameter is less
125135

126136
t.end();
127137
});
128-
129-
tape( 'the function handles null and undefined values', function test( t ) {
130-
var actual;
131-
var x;
132-
133-
x = [ 1, null, 3, undefined, 5 ];
134-
135-
actual = gjoin( x.length, ',', x, 1, 0 );
136-
t.strictEqual( actual, '1,,3,,5', 'returns expected value' );
137-
138-
t.end();
139-
});
140-
141-
tape( 'the function handles different separator types', function test( t ) {
142-
var actual;
143-
var x;
144-
145-
x = [ 1, 2, 3 ];
146-
147-
actual = gjoin( x.length, '', x, 1, 0 );
148-
t.strictEqual( actual, '123', 'returns expected value' );
149-
150-
actual = gjoin( x.length, ' - ', x, 1, 0 );
151-
t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' );
152-
153-
actual = gjoin( x.length, 0, x, 1, 0 );
154-
t.strictEqual( actual, '10203', 'returns expected value' );
155-
156-
t.end();
157-
});

0 commit comments

Comments
 (0)