Ad
Algorithms
Logic

update for ES6 with spread operator

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