Created
August 28, 2020 12:39
-
-
Save Nicknyr/1c11c8182b8604f9bacacbb06ffcfe67 to your computer and use it in GitHub Desktop.
Code Signal - Extract Matrix Column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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