use stable sort for groupBy, #35512

This commit is contained in:
Johannes Rieken
2017-10-03 09:46:35 +02:00
parent 38ae9180f9
commit 40f933d7b4
+1 -1
View File
@@ -113,7 +113,7 @@ function _divideAndMerge<T>(data: T[], compare: (a: T, b: T) => number): void {
export function groupBy<T>(data: T[], compare: (a: T, b: T) => number): T[][] {
const result: T[][] = [];
let currentGroup: T[];
for (const element of data.slice(0).sort(compare)) {
for (const element of mergeSort(data.slice(0), compare)) {
if (!currentGroup || compare(currentGroup[0], element) !== 0) {
currentGroup = [element];
result.push(currentGroup);