flip-array

0.1.0 • Public • Published

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');
  1. 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] ] ]
  1. 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

Dependencies (0)

    Dev Dependencies (7)

    Package Sidebar

    Install

    npm i flip-array

    Weekly Downloads

    0

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • tomekwi