fix(treasurechest): fix sorting #96
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"spend-sparrow/db"
|
||||
"spend-sparrow/log"
|
||||
@@ -298,6 +299,10 @@ func sortTree(nodes []*types.TreasureChest) []*types.TreasureChest {
|
||||
}
|
||||
}
|
||||
|
||||
slices.SortFunc(roots, func(a, b *types.TreasureChest) int {
|
||||
return compareStrings(a.Name, b.Name)
|
||||
})
|
||||
|
||||
for _, root := range roots {
|
||||
result = append(result, root)
|
||||
result = append(result, children[root.Id]...)
|
||||
@@ -305,3 +310,13 @@ func sortTree(nodes []*types.TreasureChest) []*types.TreasureChest {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func compareStrings(a, b string) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user