-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 22 - ExtractMatrixColumn.js
47 lines (35 loc) · 1.16 KB
/
Day 22 - ExtractMatrixColumn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Extract Matrix Column
https://scrimba.com/scrim/co3214604b3337800d868111b
Given a rectangular matrix and an integer column, return an array containing the elements
of the columnth column of the give matrix (the leftmost column is the 0th one).
Example:
For matrix = [[1,1,1,2], [0,5,0,4], [2,1,3,6]] and column = 2, the output should be
extractMatrixColumn(matrix, column) = [1,0, 3]
Hints: push()
}
*/
function extractMatrixColumn(matrix, column) {
let arr = []
for (let i = 0; i < matrix.length; i++) {
// console.log("matrix length:" + " " + matrix.length)
// console.log("matrix index:" + " " + matrix[i])
arr.push(matrix[i][column])
}
return arr
}
/**
* 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]);
});
});