concatAllArray.js.flow 805 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule concatAllArray
  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;