flatten.js 268 B

123456789101112131415
  1. 'use strict';
  2. var isArray = Array.isArray, forEach = Array.prototype.forEach;
  3. module.exports = function flatten() {
  4. var r = [];
  5. forEach.call(this, function (x) {
  6. if (isArray(x)) {
  7. r = r.concat(flatten.call(x));
  8. } else {
  9. r.push(x);
  10. }
  11. });
  12. return r;
  13. };