title: Using map and filter on multiple arrays in an object
body: <p>Using Wikipedia's API I got an object which looks like that:</p>
  
  <pre><code>obj = {["string", Array[10], Array[10], Array[10]]}
  </code></pre>
  
  <p>The first array contains <em>titles</em>, second is <em>descriptions</em> and third is <em>links</em>.</p>
  
  <p>Some of the descriptions may be empty ("").</p>
  
  <p>Example - </p>
  
  <p><img src="https://i.stack.imgur.com/BuuK0.png" alt="Example"></p>
  
  <p>I would like to combine all three arrays into one array as follow:</p>
  
  <pre><code>[{title: obj[1][0], desc: obj[2][0], link: obj[3][0]}, ... , {title: array[1][9], desc: obj[2][0], link: obj[3][0]}]
  </code></pre>
  
  <p>But <strong>only combining</strong> if description is not empty - <code>obj[2][i] !== ""</code></p>
  
  <p>I managed to do it using for loop and if:</p>
  
  <pre><code>var arr = [];
  for (var i = 0; i &lt; data[1].length; i++) {
    if (data[2][i] !== '') {
      arr.push({title: data[1][i], desc:data[2][i], link: data[3][i]});
    }
  }
  </code></pre>
  
  <p>Is there a way of achieving the same in a <strong>more elegant way</strong> using javascript's high order function? such as <code>map</code> and <code>filter</code> (maybe <code>reduce</code>?)</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The way I did it in the end was:</p>
  
  <pre><code>var resp = ["Football",
    ['Football', 'Soccer'],
    ['FootballDescription', 'SoccerDescription'],
    ['http://football.com', 'http://soccer.com']
  ];
  
  // Mimic python's zip behavior -&gt; assume arrays are of equal size
  function zip(arrays) {
    return arrays[0].map(function(_, i){
      return arrays.map(function(array){
          return array[i];
      });
    });
  }
  
  // 1. Throw away the first string, e.g. "Football"
  resp.shift();
  
  // 2. Use zip to make an array of intersected arrays, i.e
  // [
  //   ['Football', 'FootballDescription', 'http://football.com'],
  //   ['Soccer', 'SoccerDescription', 'http://soccer.com']
  // ]
  // and then use map to make each array into a nicely named object
  var objects = zip(resp).map(function(x) {
      return ({ name: x[0], desc: x[1], link: x[2] });
  });
  
  console.log(objects);
  /*
  Output:
  [ { name: 'Football',
      description: 'FootballDescription',
      link: 'http://football.com' },
    { name: 'Soccer',
      description: 'SoccerDescription',
      link: 'http://soccer.com' } ]
  */   
  </code></pre>