Nodejs Array Zip zip( fn, array )

Here you can find the source of zip( fn, array )

Method Source Code

Array.prototype.zip = function( fn, array ) {
    var ret = [];
    for ( var i = 0; i < this.length; ++i ) {
        ret.push( fn( this[ i ], array[ i ] ) );
    }//from  ww w .  j  a v a  2s  .c om

    return ret;
};

Array.cons = function( head, tail ) {
    b = [ head ];
    b.push.apply( b, tail );
    return b;
};

Array.head = function( array ) {
    return array[ 0 ];
};

Array.tail = function( array ) {
    var ret = [];
    for ( var i = 1; i < array.length; ++i ) {
        ret.push( array[ i ] );
    }

    return ret;
};

Array.prototype.head = function() {
    return Array.head( this );
};

Array.prototype.tail = function() {
    return Array.tail( this );
};

Array.prototype.sum = function() {
    return this.reduce( function( total, x ) {
        return total + x;
    }, 0 );
};

Related

  1. zip()
    Array.prototype.zip = function() {
        return this.map((value, index, arr) => {
            return arr.map((val, idx, array) => {
                return val[index];
            });
        });
    };
    
  2. zip(arr, selector)
    Array.prototype.zip = function (arr, selector) {
      return this
      .take(Math.min(this.length, arr.length))
      .select(function (t, i) {
        return selector(t, arr[i]);
      });
    };
    
  3. zip(callback)
    Array.prototype.zip = function (callback) {
        callback = callback || function (data) {
            return data;
        return this.map(callback);
    var arr = [4, 9, 16, 25];
    console.log(
        arr.zip(function (data) {
    ...
    
  4. zip(callback)
    Array.prototype.zip = function (callback) {
        callback = callback || function (data) {
            return data;
        return this.map(callback);