Ad
  1. Returns same array if already flat.
  2. Should be more efficient (1 concat call per nesting level.)
Code
Diff
  • const flatten = a => a.some(Array.isArray) ? flatten([].concat(...a)) : a
    • const flatten = a => [].concat(...a.map(x => Array.isArray(x) ? flatten(x) : x));
    • const flatten = a => a.some(Array.isArray) ? flatten([].concat(...a)) : a