title: Re-arrange array
body: <p>I need to rearrange an array in a specific way.</p>
  
  <p>My input array structure is like this (edited):</p>
  
  <pre><code>  [
      [[elem1-1,elem1-2,elem1-3],int1],
      [[elem2-1,elem2-2,elem2-3],int2]
    ]
  </code></pre>
  
  <p>Explained: "elem[n-n]" means an element and "int[n]" is an integer.</p>
  
  <p>Using structure above makes me write a very complicated loop in 2 levels to get my data and i need to rearrange the same array to look like this and avoid a second loop:</p>
  
  <pre><code>  [
      [elem1-1,int1],
      [elem1-2,int1],
      [elem1-3,int1],
      [elem2-1,int2],
      ...
    ]
  </code></pre>
  
  <p>The main difference between the arrays is the second one has all elements in row and repeats the int value for the input inline elements.</p>
  
  <p>The point is i want to rearrange this array without use of any foreach instruction (wich would result in the same 2 level loop), just doing by using map, reduce and so on.</p>
  
  <p>I tried array map, but is still not working. See code below :</p>
  
  <pre><code>      //arr_in is the first array structure and arr_out is my expected output
        var arr_out = arr_in.map( function (elem){
          if (elem[0].size()&gt;1) {
            return [//here is the problem, i guess]
          }
          else {
            return [elem[0], elem[1]]
          }
        });
  </code></pre>
  
  <p>Thanks in advance</p>