YYZ-Engine / yyz-engine

A web app for users to test algorithms
MIT License
0 stars 0 forks source link

Ychoy/issue 44 #49

Closed ychoy closed 5 years ago

ychoy commented 5 years ago
coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 198


Totals Coverage Status
Change from base Build 192: 2.5%
Covered Lines: 244
Relevant Lines: 268

💛 - Coveralls
ychoy commented 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?

zpallin commented 5 years ago

@ychoy check the issue #44

zpallin commented 5 years ago
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]]
ychoy commented 5 years ago

@zpallin please review this PR