flip-array
v0.1.0
Published
Transpose a multidimensional array.
Downloads
5
Maintainers
Readme
flip-array
Transpose a multidimensional array.
Installation
$ npm install flip-array
Usage
- Import the module:
import flip from 'flip-array/module';
// – or, in an ES5 environment:
var flip = require('flip-array');
- Profit!
flip([
[ 1 , 2 ],
[ 10 , 20 ]
]);
//» [ [ 1 , 10 ],
// [ 2 , 20 ] ]
flip([
[ 1 , 2 , [ 3 , 4 ] ],
[ 10 , 20 , [ 30 , 40 ] ],
[ 100 , 200 , [ 300 , 400 ] ]
]);
//» [ [ 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.