Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
Algorithms

This slight shuffle makes the function more robust when given non-array values. Not sure that's a desirable feature :-/

Code
Diff
  • const flatten = a => 
      Array.isArray(a) ? a.reduce((acc,item) => acc.concat(flatten(item)), []) : a;
  • 1
    const flatten = arr =>
    
    2
      arr.reduce((acc, item) =>  acc.concat(Array.isArray(item) ? flatten(item) : item), []);
    
    1+
    const flatten = a => 
    
    2+
      Array.isArray(a) ? a.reduce((acc,item) => acc.concat(flatten(item)), []) : a;