Add a ton of JS algo snippets (#56)

This commit is contained in:
Yangshun Tay
2017-10-18 17:00:48 +08:00
committed by GitHub
parent d8c3f984e4
commit d9b9d4b5ca
10 changed files with 136 additions and 13 deletions

View File

@ -0,0 +1,11 @@
function matrixTranspose(matrix) {
return matrix[0].map((col, i) => matrix.map(row => row[i]));
}
const deepEqual = require('./deepEqual');
console.log(deepEqual(matrixTranspose([[1]]), [[1]]));
console.log(deepEqual(matrixTranspose([[1, 2]]), [[1], [2]]));
console.log(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]]));