So I have the following code:
// ByTwoIndex sorts by two indices.
func ByTwoIndex(rows [][]string, idx1, idx2 int) [][]string {
idxFunc1 := func(row1, row2 *[]string) bool {
return (*row1)[idx1] < (*row2)[idx1]
}
idxFunc2 := func(row1, row2 *[]string) bool {
return (*row1)[idx2] < (*row2)[idx2]
}
by(rows, idxFunc1, idxFunc2).Sort(rows)
return rows
}
// ByTwoIndex sorts by multiple indices.
func ByMultiIndex(rows [][]string, indices ...int) [][]string {
funcSlice := []lessFunc{}
for _, idx := range indices {
idxFunc := func(row1, row2 *[]string) bool {
return (*row1)[idx] < (*row2)[idx]
}
funcSlice = append(funcSlice, idxFunc)
}
by(rows, funcSlice...).Sort(rows)
// by(rows, funcSlice[0], funcSlice[1]).Sort(rows)
// sort.Sort(by(rows, funcSlice...))
return rows
}
ByTwoIndex's results are what I expect from ByMultiIndex but for some
reason, it gets sorted by the last lessFunc in the function slices.
Can anybody help me understand what I am doing wrong in ByMultiIndex?
Thanks in advance!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.