Golang 排序

accounts := []users.Account{}
Admin.DB.Preload("CurrencyObj").Where("member_id = ?", record.(*users.Member).ID).Find(&accounts)
sort.Slice(accounts, func(i int, j int) bool {
return accounts[i].Balance > accounts[j].Balance
})
return accounts


num := []int{5,3,1,8,4,2}
slice.Sort(num, func(i int, j int) bool {
return num[i] < num[j]
}
fmt.Printf("%v\n", num) // --> []int{1, 2, 3, 4, 5, 8}
posted @ 2018-06-06 11:02  赵客缦胡缨-Nicholas  阅读(2590)  评论(2编辑  收藏  举报