Skip to content

Commit

Permalink
fix sort algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
suchen-sci committed Mar 26, 2024
1 parent 4a60223 commit 735347c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/client/resources/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ func generateTableMap(metas []*MetaSpec, namespace string) map[string]Table {
}

func tableMapToArray(tableMap map[string]Table) []Table {
res := []Table{}
for _, table := range tableMap {
res = append(res, table)
res := make([]Table, len(tableMap))
keys := make([]string, 0, len(tableMap))
for k := range tableMap {
keys = append(keys, k)
}
sort.Strings(keys)
for i, k := range keys {
res[i] = tableMap[k]
}
sort.Slice(res, func(i, j int) bool {
// res[i][0] is header, res[i][1] is first row
return res[i][1][0] < res[j][1][0]
})
return res
}

Expand Down

0 comments on commit 735347c

Please sign in to comment.