20 lines
568 B
TypeScript
20 lines
568 B
TypeScript
import { ConsRow } from "../../types/consolidations/consolidations";
|
|
export function groupAdjacent(sorted: ConsRow[]): ConsRow[] {
|
|
const order: string[] = [];
|
|
const byGroup = new Map<string, ConsRow[]>();
|
|
for (const r of sorted) {
|
|
if (!byGroup.has(r.group_id)) {
|
|
byGroup.set(r.group_id, []);
|
|
order.push(r.group_id);
|
|
}
|
|
byGroup.get(r.group_id)!.push(r);
|
|
}
|
|
const out: ConsRow[] = [];
|
|
for (const k of order) {
|
|
const g = byGroup.get(k)!;
|
|
g.sort((a, b) => a.versionIndex - b.versionIndex);
|
|
out.push(...g);
|
|
}
|
|
return out;
|
|
}
|