flatMap.js 631 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var flatMapMethod = Array.prototype.flatMap;
  7. /* eslint-disable no-redeclare */
  8. // $FlowFixMe
  9. var flatMap = flatMapMethod ? function (list, fn) {
  10. return flatMapMethod.call(list, fn);
  11. } : function (list, fn) {
  12. var result = [];
  13. for (var _i2 = 0; _i2 < list.length; _i2++) {
  14. var _item = list[_i2];
  15. var value = fn(_item);
  16. if (Array.isArray(value)) {
  17. result = result.concat(value);
  18. } else {
  19. result.push(value);
  20. }
  21. }
  22. return result;
  23. };
  24. var _default = flatMap;
  25. exports.default = _default;