Skip to content

Commit fdd59c5

Browse files
committed
Adjust transpose function not to eat '0' s
1 parent 277ff9a commit fdd59c5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/lib/__tests__/transpose-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('transpose', () => {
1818
});
1919

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

2424
expect(transposedArray.length).toBe(3);
@@ -32,7 +32,7 @@ describe('transpose', () => {
3232
expect(transposedArray[1][0]).toBe(2);
3333
expect(transposedArray[1][1]).toBe(8);
3434
expect(transposedArray[2][0]).toBe(3);
35-
expect(transposedArray[2][1]).toBe(7);
35+
expect(transposedArray[2][1]).toBe(0);
3636
});
3737

3838
it('correctly fills non symmetrical 2d arrays', () => {

src/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function transpose(originalArray) {
9595
newArray[innerIndex] = [];
9696
}
9797

98-
const value = originalArray[outerIndex][innerIndex]
98+
const value = typeof originalArray[outerIndex][innerIndex] !== 'undefined'
9999
? originalArray[outerIndex][innerIndex]
100100
: null;
101101
newArray[innerIndex].push(value);

0 commit comments

Comments
 (0)