flatMap.js 679 B

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