mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 16:42:28 +03:00
25 lines
538 B
TypeScript
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; |