flatten.js 370 B

1234567891011121314151617181920
  1. 'use strict';
  2. const internals = {};
  3. module.exports = internals.flatten = function (array, target) {
  4. const result = target || [];
  5. for (let i = 0; i < array.length; ++i) {
  6. if (Array.isArray(array[i])) {
  7. internals.flatten(array[i], result);
  8. }
  9. else {
  10. result.push(array[i]);
  11. }
  12. }
  13. return result;
  14. };