scrimba
Note at 0:55
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 0:55
AboutCommentsNotes
Note at 0:55
Expand for more info
main.js
run
preview
console
function extractMatrixColumn(matrix, column) {
let retArray = [];

// if the matrix is a valid one
let matrixRowLength = matrix[0].length;
for (let i = 0; i < matrix.length; i++) {
if (matrix[i].length != matrixRowLength) {
return retArray;
}
}

//the the required column exists
if (column < matrix[0].length) {
for (let i = 0; i < matrix.length; i++) {
retArray.push(matrix[i][column]);
}
}
return retArray;
}



/**
* Test Suite
*/
describe('extractMatrixColumn()', () => {
it('returns largest positive integer possible for digit count', () => {
// arrange
const matrix = [[1, 1, 1, 2], [0, 5, 0, 4], [2, 1, 3, 6]];
const column = 2;

// act
const result = extractMatrixColumn(matrix, column);

// log
console.log("result: ", result);

// assert
expect(result).toEqual([1, 0, 3]);
});
});


describe('extractMatrixColumn()', () => {
it('returns largest positive integer possible for digit count', () => {
// arrange
const matrix = [[1, 1, 1, 3], [0, 3, 4, 4], [2, 6, 5, 6]];
const column = 3;

// act
const result = extractMatrixColumn(matrix, column);

// log
console.log("result: ", result);

// assert
expect(result).toEqual([3, 4, 6]);
});
});

describe('extractMatrixColumn()', () => {
it('return empty array because the matrix is invalid', () => {
// arrange
const matrix = [[1, 1, 1], [0, 3, 4, 4], [2, 2, 6, 5, 6]];
const column = 3;

// act
const result = extractMatrixColumn(matrix, column);

// log
console.log("result: ", result);

// assert
expect(result).toEqual([]);
});
});

describe('extractMatrixColumn()', () => {
it('return empty array requested columnt doesnt exists', () => {
// arrange
const matrix = [[1, 1, 1,5], [0, 3, 4,4], [0, 3, 7,4]];
const column = 9;

// act
const result = extractMatrixColumn(matrix, column);

// log
console.log("result: ", result);

// assert
expect(result).toEqual([]);
});
});
Console
"result: "
,
[
1
,
0
,
3
]
,
"result: "
,
[]
,
"result: "
,
[]
,
"result: "
,
[
3
,
4
,
6
]
,
/index.html
LIVE