Skip to content

compute-io/unzip

Repository files navigation

Unzip

NPM version Build Status Coverage Status Dependencies

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

Installation

$ npm install compute-unzip

For use in the browser, use browserify.

Usage

var unzip = require( 'compute-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( 'compute-unzip' ),
	mean = require( 'compute-mean' );

// Simulate some data...
var arr = new Array( 100 ),
	len = 5;

for ( var i = 0; i < arr.length; i++ ) {
	arr[ i ] = new Array( len );
	for ( var j = 0; j < len; j++ ) {
		arr[ i ][ j ] = Math.round( Math.random()*Math.pow(10,j) );
	}
}
// Unzip and compute the means...
var out = unzip( arr );

var mu = new Array( len );
for ( var k = 0; k < len; k++ ) {
	mu[ k ] = mean( out[k] );
}
console.log( mu.join( '\t' ) );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Notes

This function is complementary to compute-zip and is inspired by Python's zip function.

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright

Copyright © 2014-2015. Athan Reines.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published