@stdlib/utils-unzip
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

Unzip

NPM version Build Status Coverage Status

Unzip a zipped array (i.e., a nested array of tuples).

Installation

npm install @stdlib/utils-unzip

Usage

var unzip = require( '@stdlib/utils-unzip' );

unzip( arr[, idx] )

Unzips a zipped array (i.e., a nested array of tuples).

var arr = [ [ 1, 'a', 3 ], [ 2, 'b', 4 ] ];

var out = unzip( arr );
// returns [ [ 1, 2 ], [ 'a', 'b' ], [ 3, 4 ] ];

To unzip specific tuple elements, you can provide an array of indices as an optional second argument.

var arr = [ [ 1, 'a', 3 ], [ 2, 'b', 4 ] ];

var out = unzip( arr, [ 0, 2 ] );
// returns [ [ 1, 2 ], [ 3, 4 ] ];

Examples

var unzip = require( '@stdlib/utils-unzip' );
var round = require( '@stdlib/math-base-special-round' );
var randu = require( '@stdlib/random-base-randu' );
var pow = require( '@stdlib/math-base-special-pow' );

var arr = new Array( 100 );
var len = 5;

var i;
var j;
for ( i = 0; i < arr.length; i++ ) {
    arr[ i ] = new Array( len );
    for ( j = 0; j < len; j++ ) {
        arr[ i ][ j ] = round( randu() * pow(10, j) );
    }
}
var out = unzip( arr );

console.dir( out );

See Also


Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2022. The Stdlib Authors.

Install

npm i @stdlib/utils-unzip

Homepage

stdlib.io

DownloadsWeekly Downloads

21

Version

0.0.8

License

Apache-2.0

Unpacked Size

38.8 kB

Total Files

9

Last publish

Collaborators

  • stdlib-bot
  • kgryte
  • planeshifter
  • rreusser