array.js 314 B

123456789101112131415
  1. 'use strict'
  2. module.exports = {
  3. flatten: function flatten (ar) {
  4. return ar.reduce((acc, item) => {
  5. if (Array.isArray(item)) {
  6. acc.push.apply(acc, flatten(item))
  7. } else {
  8. acc.push(item)
  9. }
  10. return acc
  11. }, [])
  12. }
  13. }