swc/crates/swc_bundler/tests/.cache/deno/e07fc48ca28e556adcca084ee40f7e652d4fe4c3.ts
2021-11-09 20:42:49 +09:00

25 lines
538 B
TypeScript

// Loaded from https://deno.land/x/graphql_deno@v15.0.0/lib/polyfills/flatMap.js
const flatMapMethod = Array.prototype.flatMap;
/* eslint-disable no-redeclare */
// $FlowFixMe
const flatMap = flatMapMethod ? function (list, fn) {
return flatMapMethod.call(list, fn);
} : function (list, fn) {
let result = [];
for (const item of list) {
const value = fn(item);
if (Array.isArray(value)) {
result = result.concat(value);
} else {
result.push(value);
}
}
return result;
};
export default flatMap;