0.1.0 • Published 9 years ago

flip-array v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Coveralls – test coverage
Travis – build status
David – status of dependencies
Code style: airbnb

flip-array

Transpose a multidimensional array.

Installation

$ npm install flip-array

Usage

1) Import the module:

import flip from 'flip-array/module';

// – or, in an ES5 environment:
var flip = require('flip-array');

2) 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] ] ]

3) 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.

License

MIT © Tomek Wiszniewski