title: How do I recursively use the reduce() method in javascript?
body: <p>The question is to use reduce() to operate on an array of arrays and return a homogeneous array with no sub-arrays.
  Eg - [1,2,[3,[4,5]]] will return [1,2,3,4,5].</p>
  
  <p>Here is code that works, considering the sub-array itself is not another array of arrays-   </p>
  
  <pre><code>var a = [3,[4,[5,[6,7]]]];
  var b = 8;
  var c = [9,10];
  var x = []
  
  var arr = [1,2,a,b,c];
  arr = [1,2,3,4,c];
  
  console.log(arr.reduce(function oneArray(a,b)
      {
          return a.concat(b); 
      },x))
  </code></pre>
  
  <p>Notice that I change my arr array as the code does not work for the first arr array i.e [1,2,a,b,c].
  For arr [1,2,3,4,c] the object returned is [1,2,3,4,9,10]</p>
  
  <p>Here is my attempt to make it work for the first arr-</p>
  
  <pre><code>function oneArray(a,b)
      {
          if (typeof b == "object")
              b = b.reduce(oneArray(x,y),[]);
          return a.concat(b); 
      }
  
      console.log(arr.reduce(oneArray(a,b),x));
  </code></pre>
  
  <p>This gives me the error </p>
  
  <p>Uncaught TypeError: [object Array] is not a function(anonymous function) @ Flattening.html:27</p>
  
  <p>It interprets my function oneArray as an array not a function</p>
  
  <p>I understand the problem comes from the fact that reduce can (I think) work only with a function defined as a parameter.
  Does anyone have a solution so that I get [1,2,3,4,5,6,78,9,10] as my result working around the limitations of reduce() unless I missed something?</p>