time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2108B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # Unzip
     22 
     23 > Unzip a [zipped array][@stdlib/utils/zip] (i.e., a nested array of tuples).
     24 
     25 <section class="intro">
     26 
     27 </section>
     28 
     29 <!-- /.intro -->
     30 
     31 <section class="usage">
     32 
     33 ## Usage
     34 
     35 ```javascript
     36 var unzip = require( '@stdlib/utils/unzip' );
     37 ```
     38 
     39 #### unzip( arr\[, idx] )
     40 
     41 Unzips a [zipped array][@stdlib/utils/zip] (i.e., a nested `array` of tuples).
     42 
     43 ```javascript
     44 var arr = [ [ 1, 'a', 3 ], [ 2, 'b', 4 ] ];
     45 
     46 var out = unzip( arr );
     47 // returns [ [ 1, 2 ], [ 'a', 'b' ], [ 3, 4 ] ];
     48 ```
     49 
     50 To unzip specific tuple elements, you can provide an `array` of indices as an optional second argument.
     51 
     52 ```javascript
     53 var arr = [ [ 1, 'a', 3 ], [ 2, 'b', 4 ] ];
     54 
     55 var out = unzip( arr, [ 0, 2 ] );
     56 // returns [ [ 1, 2 ], [ 3, 4 ] ];
     57 ```
     58 
     59 </section>
     60 
     61 <!-- /.usage -->
     62 
     63 <section class="examples">
     64 
     65 ## Examples
     66 
     67 <!-- eslint no-undef: "error" -->
     68 
     69 ```javascript
     70 var unzip = require( '@stdlib/utils/unzip' );
     71 var round = require( '@stdlib/math/base/special/round' );
     72 var randu = require( '@stdlib/random/base/randu' );
     73 var pow = require( '@stdlib/math/base/special/pow' );
     74 
     75 var arr;
     76 var len;
     77 var out;
     78 var i;
     79 var j;
     80 
     81 arr = new Array( 100 );
     82 len = 5;
     83 
     84 for ( i = 0; i < arr.length; i++ ) {
     85     arr[ i ] = new Array( len );
     86     for ( j = 0; j < len; j++ ) {
     87         arr[ i ][ j ] = round( randu() * pow(10, j) );
     88     }
     89 }
     90 out = unzip( arr );
     91 
     92 console.dir( out );
     93 ```
     94 
     95 </section>
     96 
     97 <!-- /.examples -->
     98 
     99 <section class="links">
    100 
    101 [@stdlib/utils/zip]: https://www.npmjs.com/package/@stdlib/utils/tree/main/zip
    102 
    103 </section>
    104 
    105 <!-- /.links -->