I'm trying to flatten a nested array but I'm getting undefined. I recently learnt reduce and am trying to apply the same logic.
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));I get undefined. Why? What am I missing?
 
     
    