flatMap.mjs 497 B

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