Closed ychoy closed 5 years ago
TODO - refactor matrix_flip so that it can take a matrix of N size. @zpallin - can you please give me an example of a 3-D or other N-dimensional input matrix, and the output example for matrix_flip?
@ychoy check the issue #44
function transpose(array) {
return array.reduce((prev, next) => next.map((item, i) =>
(prev[i] || []).concat(next[i])
), []);
}
console.log(transpose([[0, 1], [2, 3], [4, 5]]));
1. (null, [0, 1])
next.map(0, 0) // val , idx
prev[0] || [] -> [] .concat next[i] -> [0]
next.map(1, 1)
prev[1] || [] -> [] .concat next[i] -> [1]
[[0],[1]]
2. ([[0],[1]], [2, 3])
next.map(2, 0)
prev[0] || [] -> [0] concat next[0] -> [0, 2]
next.map(3, 1)
prev[1] || [] -> [1] concat next[1] -> [1, 3]
3. ([[0, 2], [1, 3]], [4, 5])
next.map(4, 0)
prev[0] || [] -> [0, 2] concat next[0] -> [0, 2, 4]
next.map(5, 1)
prev[1] || [] -> [1, 3] concat next[1] -> [1, 3, 5]
[[0, 2, 4], [1, 3, 5]]
@zpallin please review this PR