title: Flattening nested array
body: <p>I'm trying to flatten a nested array but I'm getting undefined. I recently learnt <code>reduce</code> and am trying to apply the same logic.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var list2 = [0, [1, [2, [3, [4, [5]]]]]];
  
  function flat3(arr){
    arr.reduce(function(result, val, index){
      if(Array.isArray(val)){
        result = result.concat(val);
        flat3(val);
      } else {
        result.push(val);
      }
      return result;
    }, []);
  }
  
  console.log(flat3(list2));</code></pre>
  </div>
  </div>
  </p>
  
  <p>I get undefined. Why? What am I missing?</p>