Thanks guys for such a quick response.
I plan on using the sort.Slice method.
I looked at the SortKeys example and that will take much more study for
me to understand it.
--rob solomon
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsub
You could define multiple types:
type bySubtotal []directory
type byName []directory
which have different Sort methods.
You could also define a type that includes a func(d0, d1 directory)
bool. The SortKeys example in the sort package docs
(https://golang.org/pkg/sort/#example__sortMultiKeys) co
Look at the "Example (SortKeys)" part of https://golang.org/pkg/sort/
-rob
On Wed, Nov 8, 2017 at 12:38 PM, rob wrote:
> Hi. I am trying to sort a slice of a struct using one of two different
> fields.
>
> type directory struct {
> name string
> subtotal int64
> }
>
> type dirslic
Hi. I am trying to sort a slice of a struct using one of two different
fields.
type directory struct {
name string
subtotal int64
}
type dirslice []directory
I want to sort a var of type dirslice by either name or subtotal. I
understand how to sort by one of those, by defining