Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created August 28, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/1c11c8182b8604f9bacacbb06ffcfe67 to your computer and use it in GitHub Desktop.
Save Nicknyr/1c11c8182b8604f9bacacbb06ffcfe67 to your computer and use it in GitHub Desktop.
Code Signal - Extract Matrix Column
/*
Given a rectangular matrix and an integer column, return an array containing the elements of the columnth column of the given 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].
*/
function extractMatrixColumn(matrix, column) {
let newArr = [];
for(let i = 0; i < matrix.length; i++) {
newArr.push(matrix[i][column]);
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment