concatAllArray.js 786 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. /**
  3. * Copyright (c) 2013-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. *
  8. * @typechecks
  9. */
  10. var push = Array.prototype.push;
  11. /**
  12. * Concats an array of arrays into a single flat array.
  13. *
  14. * @param {array} array
  15. * @return {array}
  16. */
  17. function concatAllArray(array) {
  18. var ret = [];
  19. for (var ii = 0; ii < array.length; ii++) {
  20. var value = array[ii];
  21. if (Array.isArray(value)) {
  22. push.apply(ret, value);
  23. } else if (value != null) {
  24. throw new TypeError('concatAllArray: All items in the array must be an array or null, ' + 'got "' + value + '" at index "' + ii + '" instead');
  25. }
  26. }
  27. return ret;
  28. }
  29. module.exports = concatAllArray;