Unzip

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

    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;
    var len;
    var out;
    var i;
    var j;
    
    arr = new Array( 100 );
    len = 5;
    
    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) );
        }
    }
    out = unzip( arr );
    
    console.dir( out );