Skip to content

Commit f53879d

Browse files
committed
fix: ensure support for outer accessor arrays
--- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0c087b7 commit f53879d

File tree

6 files changed

+111
-16
lines changed

6 files changed

+111
-16
lines changed

lib/node_modules/@stdlib/array/base/zip/lib/main.js

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

2323
var resolveGetter = require( '@stdlib/array/base/resolve-getter' );
24+
var copy = require( '@stdlib/array/base/copy' );
2425

2526

2627
// MAIN //
@@ -44,6 +45,7 @@ var resolveGetter = require( '@stdlib/array/base/resolve-getter' );
4445
*/
4546
function zip( arrays ) {
4647
var getters;
48+
var list;
4749
var out;
4850
var arr;
4951
var M;
@@ -55,19 +57,20 @@ function zip( arrays ) {
5557
if ( M < 1 ) {
5658
return [];
5759
}
58-
N = arrays[ 0 ].length;
60+
list = copy( arrays );
61+
N = list[ 0 ].length;
5962
if ( N < 1 ) {
6063
return [];
6164
}
6265
getters = [];
6366
for ( j = 0; j < M; j++ ) {
64-
getters.push( resolveGetter( arrays[ j ] ) );
67+
getters.push( resolveGetter( list[ j ] ) );
6568
}
6669
out = [];
6770
for ( i = 0; i < N; i++ ) {
6871
arr = [];
6972
for ( j = 0; j < M; j++ ) {
70-
arr.push( getters[ j ]( arrays[ j ], i ) );
73+
arr.push( getters[ j ]( list[ j ], i ) );
7174
}
7275
out.push( arr );
7376
}

lib/node_modules/@stdlib/array/base/zip/test/test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tape( 'main export is a function', function test( t ) {
3333
t.end();
3434
});
3535

36-
tape( 'the function returns an empty array if provided no input arrays', function test( t ) {
36+
tape( 'the function returns an empty array if provided no input arrays (indexed)', function test( t ) {
3737
var expected;
3838
var actual;
3939

@@ -44,7 +44,18 @@ tape( 'the function returns an empty array if provided no input arrays', functio
4444
t.end();
4545
});
4646

47-
tape( 'the function returns an empty array if provided empty input arrays', function test( t ) {
47+
tape( 'the function returns an empty array if provided no input arrays (accessors)', function test( t ) {
48+
var expected;
49+
var actual;
50+
51+
actual = zip( toAccessorArray( [] ) );
52+
expected = [];
53+
t.deepEqual( actual, expected, 'returns expected value' );
54+
55+
t.end();
56+
});
57+
58+
tape( 'the function returns an empty array if provided empty input arrays (indexed)', function test( t ) {
4859
var expected;
4960
var actual;
5061

@@ -55,6 +66,20 @@ tape( 'the function returns an empty array if provided empty input arrays', func
5566
t.end();
5667
});
5768

69+
tape( 'the function returns an empty array if provided empty input arrays (accessors)', function test( t ) {
70+
var expected;
71+
var actual;
72+
var x;
73+
74+
x = toAccessorArray( [ toAccessorArray( [] ), toAccessorArray( [] ) ] );
75+
76+
actual = zip( x );
77+
expected = [];
78+
t.deepEqual( actual, expected, 'returns expected value' );
79+
80+
t.end();
81+
});
82+
5883
tape( 'the function zips one array to an array of arrays (indexed)', function test( t ) {
5984
var expected;
6085
var actual;

lib/node_modules/@stdlib/array/base/zip2objects/lib/main.js

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

2323
var resolveGetter = require( '@stdlib/array/base/resolve-getter' );
24+
var copy = require( '@stdlib/array/base/copy' );
2425

2526

2627
// MAIN //
@@ -48,6 +49,7 @@ var resolveGetter = require( '@stdlib/array/base/resolve-getter' );
4849
*/
4950
function zip2objects( arrays, labels ) {
5051
var getters;
52+
var list;
5153
var keys;
5254
var get;
5355
var out;
@@ -61,7 +63,8 @@ function zip2objects( arrays, labels ) {
6163
if ( M < 1 ) {
6264
return [];
6365
}
64-
N = arrays[ 0 ].length;
66+
list = copy( arrays );
67+
N = list[ 0 ].length;
6568
if ( N < 1 ) {
6669
return [];
6770
}
@@ -70,14 +73,14 @@ function zip2objects( arrays, labels ) {
7073
get = resolveGetter( labels );
7174
keys = [];
7275
for ( j = 0; j < M; j++ ) {
73-
getters.push( resolveGetter( arrays[ j ] ) );
76+
getters.push( resolveGetter( list[ j ] ) );
7477
keys.push( get( labels, j ) );
7578
}
7679
out = [];
7780
for ( i = 0; i < N; i++ ) {
7881
obj = {};
7982
for ( j = 0; j < M; j++ ) {
80-
obj[ keys[ j ] ] = getters[ j ]( arrays[ j ], i );
83+
obj[ keys[ j ] ] = getters[ j ]( list[ j ], i );
8184
}
8285
out.push( obj );
8386
}

lib/node_modules/@stdlib/array/base/zip2objects/test/test.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tape( 'main export is a function', function test( t ) {
3333
t.end();
3434
});
3535

36-
tape( 'the function returns an empty array if provided no input arrays', function test( t ) {
36+
tape( 'the function returns an empty array if provided no input arrays (indexed)', function test( t ) {
3737
var expected;
3838
var actual;
3939
var labels;
@@ -47,7 +47,21 @@ tape( 'the function returns an empty array if provided no input arrays', functio
4747
t.end();
4848
});
4949

50-
tape( 'the function returns an empty array if provided empty input arrays', function test( t ) {
50+
tape( 'the function returns an empty array if provided no input arrays (accessors)', function test( t ) {
51+
var expected;
52+
var actual;
53+
var labels;
54+
55+
labels = [];
56+
57+
actual = zip2objects( toAccessorArray( [] ), labels );
58+
expected = [];
59+
t.deepEqual( actual, expected, 'returns expected value' );
60+
61+
t.end();
62+
});
63+
64+
tape( 'the function returns an empty array if provided empty input arrays (indexed)', function test( t ) {
5165
var expected;
5266
var actual;
5367
var labels;
@@ -61,6 +75,23 @@ tape( 'the function returns an empty array if provided empty input arrays', func
6175
t.end();
6276
});
6377

78+
tape( 'the function returns an empty array if provided empty input arrays (accessors)', function test( t ) {
79+
var expected;
80+
var actual;
81+
var labels;
82+
var x;
83+
84+
labels = [ 'x', 'y' ];
85+
86+
x = toAccessorArray( [ toAccessorArray( [] ), toAccessorArray( [] ) ] );
87+
88+
actual = zip2objects( x, labels );
89+
expected = [];
90+
t.deepEqual( actual, expected, 'returns expected value' );
91+
92+
t.end();
93+
});
94+
6495
tape( 'the function zips one array to an array of objects (indexed)', function test( t ) {
6596
var expected;
6697
var actual;

lib/node_modules/@stdlib/array/base/zip2views/lib/main.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var copy = require( '@stdlib/array/base/copy' );
7777
function zip2views( arrays, labels ) {
7878
var getter;
7979
var setter;
80+
var list;
8081
var keys;
8182
var out;
8283
var acc;
@@ -89,14 +90,15 @@ function zip2views( arrays, labels ) {
8990
if ( M < 1 ) {
9091
return [];
9192
}
92-
N = arrays[ 0 ].length;
93+
list = copy( arrays );
94+
N = list[ 0 ].length;
9395
if ( N < 1 ) {
9496
return [];
9597
}
9698
// Resolve element accessors...
9799
acc = [];
98100
for ( j = 0; j < M; j++ ) {
99-
acc.push( accessors( arrays[ j ] ).accessors );
101+
acc.push( accessors( list[ j ] ).accessors );
100102
}
101103
// Create a copy of provided labels to prevent external mutation:
102104
keys = copy( labels );
@@ -117,8 +119,8 @@ function zip2views( arrays, labels ) {
117119

118120
// Define read/write accessors for each label...
119121
for ( j = 0; j < M; j++ ) {
120-
getter = getValue( arrays[ j ], acc[ j ][ 0 ] );
121-
setter = setValue( arrays[ j ], acc[ j ][ 1 ] );
122+
getter = getValue( list[ j ], acc[ j ][ 0 ] );
123+
setter = setValue( list[ j ], acc[ j ][ 1 ] );
122124
setReadWriteAccessor( Datum.prototype, keys[ j ], getter, setter );
123125
}
124126
// Ensure that the returned array correctly serializes to JSON:

lib/node_modules/@stdlib/array/base/zip2views/test/test.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) {
3434
t.end();
3535
});
3636

37-
tape( 'the function returns an empty array if provided no input arrays', function test( t ) {
37+
tape( 'the function returns an empty array if provided no input arrays (indexed)', function test( t ) {
3838
var expected;
3939
var actual;
4040
var labels;
@@ -48,7 +48,21 @@ tape( 'the function returns an empty array if provided no input arrays', functio
4848
t.end();
4949
});
5050

51-
tape( 'the function returns an empty array if provided empty input arrays', function test( t ) {
51+
tape( 'the function returns an empty array if provided no input arrays (accessors)', function test( t ) {
52+
var expected;
53+
var actual;
54+
var labels;
55+
56+
labels = [];
57+
58+
actual = zip2views( toAccessorArray( [] ), labels );
59+
expected = [];
60+
t.deepEqual( actual, expected, 'returns expected value' );
61+
62+
t.end();
63+
});
64+
65+
tape( 'the function returns an empty array if provided empty input arrays (indexed)', function test( t ) {
5266
var expected;
5367
var actual;
5468
var labels;
@@ -62,6 +76,23 @@ tape( 'the function returns an empty array if provided empty input arrays', func
6276
t.end();
6377
});
6478

79+
tape( 'the function returns an empty array if provided empty input arrays (accessors)', function test( t ) {
80+
var expected;
81+
var actual;
82+
var labels;
83+
var x;
84+
85+
labels = [ 'x', 'y' ];
86+
87+
x = toAccessorArray( [ toAccessorArray( [] ), toAccessorArray( [] ) ] );
88+
89+
actual = zip2views( x, labels );
90+
expected = [];
91+
t.deepEqual( actual, expected, 'returns expected value' );
92+
93+
t.end();
94+
});
95+
6596
tape( 'the function zips one array to an array of objects (indexed)', function test( t ) {
6697
var expected;
6798
var actual;

0 commit comments

Comments
 (0)