You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
550 B
34 lines
550 B
7 years ago
|
function matrixTranspose(matrix) {
|
||
2 years ago
|
return matrix[0].map((col, i) => matrix.map((row) => row[i]));
|
||
7 years ago
|
}
|
||
|
|
||
|
const deepEqual = require('./deepEqual');
|
||
|
|
||
|
console.log(deepEqual(matrixTranspose([[1]]), [[1]]));
|
||
|
console.log(deepEqual(matrixTranspose([[1, 2]]), [[1], [2]]));
|
||
5 years ago
|
console.log(
|
||
2 years ago
|
deepEqual(
|
||
|
matrixTranspose([
|
||
|
[1, 2],
|
||
|
[1, 4],
|
||
|
]),
|
||
|
[
|
||
|
[1, 1],
|
||
|
[2, 4],
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
console.log(
|
||
|
deepEqual(
|
||
|
matrixTranspose([
|
||
|
[1, 2, 3],
|
||
|
[4, 5, 6],
|
||
|
]),
|
||
|
[
|
||
|
[1, 4],
|
||
|
[2, 5],
|
||
|
[3, 6],
|
||
|
],
|
||
|
),
|
||
5 years ago
|
);
|