function extractMatrixColumn(matrix, column) {
return matrix.map((innerArray) => innerArray[column] )
}
/**
* Test Suite
*/
describe('extractMatrixColumn()', () => {
it('returns the element from nested arrays at column (index)', () => {
// 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('returns the element from nested arrays at column (index)', () => {
// arrange
const matrix = [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10, 11, 12]];
const column = 2;
// act
const result = extractMatrixColumn(matrix, column);
// log
console.log("result: ", result);
// assert
expect(result).toEqual([3, 7, 10]);
});
});