Created
July 20, 2017 02:45
-
-
Save formigone/6614e7937ce0d25dfa3dbcbb4b44efcf to your computer and use it in GitHub Desktop.
Computes the transpose of a matrix represented by a 2-dimensional array
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
function transpose(mat){ | |
return mat[0].map((_, y) => { | |
return mat.map((_, x) => { | |
return mat[x][y]; | |
}); | |
}); | |
} | |
var mat0 = [ | |
[0, 1, 2, 3, 4], | |
[5, 6, 7, 8, 9], | |
]; | |
transpose(mat0); | |
// [ | |
// [0, 5], | |
// [1, 6], | |
// [2, 7], | |
// [3, 8], | |
// [4, 9], | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment