Skip to main content
Deno 2 is finally here 🎉️
Learn more

transpose-array

npm version deno version CI Coverage Status
code style: prettier GitHub Discussions BSD 3 Clause license Commitizen friendly semantic-release

Perform the matrix operation transpose on an array respecting type information.

Any donations would be much appreciated. 😄

Installation

Node

# Install with npm
npm install transpose-array

# Install with pnpm
pnpm add transpose-array

# Install with yarn
yarn add transpose-array

Deno

// import_map.json
{
  "imports": {
    "transpose-array": "https://deno.land/x/transposearray@__version__/dist/deno/index.ts"
  }
}

Usage

import transpose from "transpose-array";

const data = [
  ['a', 'b', 'c', 'd'],
  ['e', 'f', 'g', 'h'],
  ['i', 'j', 'k', 'l'],
]

const transposedData = transpose(data);
// => [
//   ['a', 'e', 'i'],
//   ['b', 'f', 'j'],
//   ['c', 'g', 'k'],
//   ['d', 'h', 'l'],
// ]

API

transpose(array) [default]

Create a new array which is a transposed version of the given array.

transposeInPlace(array)

Modifies the given array in order to transpose it.