Re: [go-nuts] Sorting slice of structs

2018-04-10 Thread Michael Jones
We all saw it immediately ... because ... we remember having done it too. :-) On Tue, Apr 10, 2018 at 11:38 AM, Sankar wrote: > ah damn. Thanks everyone :) > > On Wednesday, 11 April 2018 00:05:00 UTC+5:30, Jan Mercl wrote: >> >> >> On Tue, Apr 10, 2018 at 8:29 PM

Re: [go-nuts] Sorting slice of structs

2018-04-10 Thread Sankar
ah damn. Thanks everyone :) On Wednesday, 11 April 2018 00:05:00 UTC+5:30, Jan Mercl wrote: > > > On Tue, Apr 10, 2018 at 8:29 PM Sankar > wrote: > > > Any help on how I can get arr sorted in the above code ? > > Just a typo: https://play.golang.org/p/vhbo8OIrh-H > > --

Re: [go-nuts] Sorting slice of structs

2018-04-10 Thread Jan Mercl
On Tue, Apr 10, 2018 at 8:29 PM Sankar wrote: > Any help on how I can get arr sorted in the above code ? Just a typo: https://play.golang.org/p/vhbo8OIrh-H -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group.

Re: [go-nuts] Sorting slice of structs

2018-04-10 Thread Burak Serdar
Simple mistake. You have: sort.Slice(arr, func(i, j int) bool { return arr[i].X < arr[i].X }) Instead use: sort.Slice(arr, func(i, j int) bool { return arr[i].X < arr[j].X }) On Tue, Apr 10, 2018 at 12:28 PM, Sankar wrote: > Hi > > I have the following code: > >

Re: [go-nuts] Sorting slice of structs

2018-04-10 Thread Michael Jones
Change I i to I j On Tue, Apr 10, 2018 at 11:29 AM Sankar wrote: > Hi > > I have the following code: > > type Point struct { > Xint > Name string > } > > arr := []Point{ > Point{1, "One"}, > Point{3, "Three"}, > Point{2, "Two"}, > Point{4, "Four"}, > } > >

[go-nuts] Sorting slice of structs

2018-04-10 Thread Sankar
Hi I have the following code: type Point struct { Xint Name string } arr := []Point{ Point{1, "One"}, Point{3, "Three"}, Point{2, "Two"}, Point{4, "Four"}, } log.Println("Before Sorting: ", arr) sort.Slice(arr, func(i, j int) bool { return arr[i].X < arr[i].X }) log.Println("After Sorting:

Re: [go-nuts] Sorting slice of structs

2016-09-20 Thread xingtao zhao
Or: sort.Sort(Courses(course)) On Tuesday, September 20, 2016 at 10:50:15 AM UTC-7, Jan Mercl wrote: > > Types []Course and Courses are distinct types. courses have type []Courses > because that's what the parameter to make is. Change it to Courses, ie. > > courses := make(Courses, maxrow) > >

Re: [go-nuts] Sorting slice of structs

2016-09-20 Thread Jan Mercl
Types []Course and Courses are distinct types. courses have type []Courses because that's what the parameter to make is. Change it to Courses, ie. courses := make(Courses, maxrow) On Tue, Sep 20, 2016, 19:44 Arie van Wingerden wrote: > Hi, > > Still a beginner ... first take

[go-nuts] Sorting slice of structs

2016-09-20 Thread Arie van Wingerden
Hi, Still a beginner ... first take at a bit more difficult thing. I cannot get this https://play.golang.org/p/qgBLH0r_vq to work. Compiler says: cannot use courses (type []Course) as type sort.Interface in argument to sort.Sort: []Course does not implement sort.Interface (missing Len