Unzips a zipped array (i.e., a nested array of tuples).
$ npm install compute-unzip
For use in the browser, use browserify.
var unzip = require( 'compute-unzip' );
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] ];
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
This function is complementary to compute-zip and is inspired by Python's zip
function.
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.
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
Copyright © 2014-2015. Athan Reines.