flip-array
Transpose a multidimensional array.
Installation
$ npm install flip-array
Usage
- Import the module:
; // – or, in an ES5 environment:var flip = ;
- Profit!
;//» [ [ 1 , 10 ],// [ 2 , 20 ] ] ;//» [ [ 1 , 10 , 100 ],// [ 2 , 20 , 200 ],// [ [3, 4] , [30, 40] , [300, 400] ] ]
- Huh?
https://en.wikipedia.org/wiki/Transpose
Input:
[[1, 2], [10, 20]]
Matrix:
┌ ┐
│ 1 2 │
│ 10 20 │
└ ┘
Transposed:
┌ ┐
│ 1 10 │
│ 2 20 │
└ ┘
Output:
[[1, 10], [2, 20]]
API
flip(array)
Transposes the given two-dimensional array as if it were a matrix.
Returns a new array, flipped against the diagonal of the matrix.
Parameters:
Array[]
array
A two-dimensional array
Return value:
Array[]
A copy of array, transposed.