index.js 455 B

123456789101112131415161718192021222324252627
  1. /*!
  2. * arr-flatten <https://github.com/jonschlinkert/arr-flatten>
  3. *
  4. * Copyright (c) 2014-2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. module.exports = function flatten(arr) {
  9. return flat(arr, []);
  10. };
  11. function flat(arr, res) {
  12. var len = arr.length;
  13. var i = -1;
  14. while (len--) {
  15. var cur = arr[++i];
  16. if (Array.isArray(cur)) {
  17. flat(cur, res);
  18. } else {
  19. res.push(cur);
  20. }
  21. }
  22. return res;
  23. }