flatMap.mjs 545 B

123456789101112131415161718192021222324
  1. // Workaround to make older Flow versions happy
  2. var flatMapMethod = Array.prototype.flatMap;
  3. /* eslint-disable no-redeclare */
  4. // $FlowFixMe
  5. var flatMap = flatMapMethod ? function (list, fn) {
  6. return flatMapMethod.call(list, fn);
  7. } : function (list, fn) {
  8. var result = [];
  9. for (var _i2 = 0; _i2 < list.length; _i2++) {
  10. var _item = list[_i2];
  11. var value = fn(_item);
  12. if (Array.isArray(value)) {
  13. result = result.concat(value);
  14. } else {
  15. result.push(value);
  16. }
  17. }
  18. return result;
  19. };
  20. export default flatMap;