Skip to content

Adjust transpose function not to eat '0' s #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-chart-editor",
"description": "plotly.js chart editor react component UI",
"version": "0.17.0",
"version": "0.17.1",
"author": "Plotly, Inc.",
"bugs": {
"url": "https://github.com/plotly/react-chart-editor/issues"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/transpose-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('transpose', () => {
});

it('correctly transposes 2d arrays', () => {
const originalArray = [[1, 2, 3], [9, 8, 7]];
const originalArray = [[1, 2, 3], [9, 8, 0]];
const transposedArray = transpose(originalArray);

expect(transposedArray.length).toBe(3);
Expand All @@ -32,7 +32,7 @@ describe('transpose', () => {
expect(transposedArray[1][0]).toBe(2);
expect(transposedArray[1][1]).toBe(8);
expect(transposedArray[2][0]).toBe(3);
expect(transposedArray[2][1]).toBe(7);
expect(transposedArray[2][1]).toBe(0);
});

it('correctly fills non symmetrical 2d arrays', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ function transpose(originalArray) {
newArray[innerIndex] = [];
}

const value = originalArray[outerIndex][innerIndex]
? originalArray[outerIndex][innerIndex]
: null;
const value =
typeof originalArray[outerIndex][innerIndex] !== 'undefined'
? originalArray[outerIndex][innerIndex]
: null;
newArray[innerIndex].push(value);
}
}
Expand Down