mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
12 lines
358 B
TypeScript
12 lines
358 B
TypeScript
/**
|
|
* Calls a defined callback function on each element of an array.
|
|
* Then, flattens the result into a new array.
|
|
*/
|
|
export function flatMap<U, T>(array: T[], callback: (value: T, index: number, array: T[]) => U[]): U[] {
|
|
const result: U[] = [];
|
|
array.map<U[]>(callback).forEach(arr => {
|
|
result.push(...arr);
|
|
});
|
|
return result;
|
|
}
|