function extractMatrixColumn(matrix, column) {
if (matrix.length === 0 || matrix[0].length === 0) {
throw 'input matrix is empty'
} else if (matrix[0].length < column) {
throw 'column is outside of matrix bounds'
}
const col = [];
for (row of matrix) {
col.push(row[column]);
}
return col;
}
/**
* 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]);
});
it('throws an error if matrix is empty', () => {
const matrix = [];
const column = 2;
const error = 'input matrix is empty';
expect(() => extractMatrixColumn(matrix, column)).toThrow(error);
});
it('throws an error if matrix row is empty', () => {
const matrix = [[]];
const column = 2;
const error = 'input matrix is empty';
expect(() => extractMatrixColumn(matrix, column)).toThrow(error);
});
it('throws an error if column is invalid', () => {
const matrix = [[1],[2]];
const column = 2;
const error = 'column is outside of matrix bounds';
expect(() => extractMatrixColumn(matrix, column)).toThrow(error);
});
});