Skip to content

Commit d3b0f25

Browse files
committed
fix: correct loop bounds in toJSON method for nested2views
--- 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 fbc5910 commit d3b0f25

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function nested2views( arr, fields ) {
204204
var i;
205205

206206
out = {};
207-
for ( i = 0; i < M; i++ ) {
207+
for ( i = 0; i < N; i++ ) {
208208
k = keys[ i ];
209209
out[ k ] = this[ k ];
210210
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,36 @@ tape( 'the function supports outer array mutation (accessors)', function test( t
289289

290290
t.end();
291291
});
292+
293+
tape( 'the returned views have a toJSON method which includes all fields', function test( t ) {
294+
var expected;
295+
var actual;
296+
var fields;
297+
var x;
298+
299+
fields = [ 'a', 'b', 'c', 'd', 'e' ];
300+
301+
x = [ [ 1, 2, 3, 4, 5 ], [ 6, 7, 8, 9, 10 ] ];
302+
303+
actual = nested2views( x, fields );
304+
305+
expected = {
306+
'a': 1,
307+
'b': 2,
308+
'c': 3,
309+
'd': 4,
310+
'e': 5
311+
};
312+
t.deepEqual( actual[ 0 ].toJSON(), expected, 'returns expected value for first element' );
313+
314+
expected = {
315+
'a': 6,
316+
'b': 7,
317+
'c': 8,
318+
'd': 9,
319+
'e': 10
320+
};
321+
t.deepEqual( actual[ 1 ].toJSON(), expected, 'returns expected value for second element' );
322+
323+
t.end();
324+
});

0 commit comments

Comments
 (0)