scrimba
Note at 1:05
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 1:05
AboutCommentsNotes
Note at 1:05
Expand for more info
main.js
run
preview
console
function extractMatrixColumn(matrix, col) {
let Array = [];
matrix.forEach((array) => array.length <= col || col < 0 ? 0 : Array.push(array[col]))
return Array;
}



/**
* Test Suite
*/
describe('extractMatrixColumn()', () => {
it('returns largest positive integer possible for digit count', () => {
const matrix = [[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]];
const column = 2;
const result = extractMatrixColumn(matrix, column);
console.log("result: ", result);
expect(result).toEqual([1, 0, 3]);
});

it('returns empty array in case of index out of limit', () => {
// arrange
const matrix = [[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]];
const column = 4;
const result = extractMatrixColumn(matrix, column);
console.log("result1: ", result);
expect(result).toEqual([]);
});

it('returns empty array in case of negative index', () => {
const matrix = [[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]];
const column = -4;
const result = extractMatrixColumn(matrix, column);
console.log("result2: ", result);
expect(result).toEqual([]);
});

it('returns largest positive integer possible in case of mixed length inner arrays', () => {
const matrix = [[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3]];
const column = 3;
const result = extractMatrixColumn(matrix, column);
console.log("result3: ", result);
expect(result).toEqual([2,4]);
});
});
Console
"result2: "
,
[]
,
"result3: "
,
[
2
,
4
]
,
"result: "
,
[
1
,
0
,
3
]
,
"result1: "
,
[]
,
/index.html
LIVE