Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Jérôme Champion
As itinerary and the reslicing operation use the same backing array, you could just offset your indexes: https://play.golang.org/p/2ZzKST5J1g I'm not sure if it's a good idea, could the sort.Slice implementation change in the future and make a regression? Le mercredi 8 mars 2017 18:22:48 UTC+1,

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Ain
Another, OO-ish fix is to use method on custom type (https://play.golang.org/p/a5S5rNog5h): type itinerary []string func (t itinerary) sort() { sort.Slice(t, func(i, j int) bool { return t[i] < t[j] }) } func main() { itinerary := itinerary{"Philadelphia", "Chicago", "Bosto

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread David Peacock
On Wed, Mar 8, 2017 at 10:01 AM, Val wrote: > Sorry for not elaborating in the first place (I was trying to make the > point very concise). > Thank you for detailing further! :-) > The bug in my code is that the two arguments I pass to sort.Slice are > inconsistent : the portion to be sorted is

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread James Bardin
On Wednesday, March 8, 2017 at 10:01:08 AM UTC-5, Val wrote: > > > - or the code in the less function will have to refer to the same > (unnamed) resliced portion, which is imo convoluted : fix 1 > or fix 2 > . > Hav

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Val
Sorry for not elaborating in the first place (I was trying to make the point very concise). This is the starting city : Philadelphia This are the other cities : Chicago, Boston, Austin The itinerary is the concatenation of starting city + other cities to be visited : [Philadelphia, Chicag

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread David Peacock
On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace wrote: > I did explain the expected result : "and I want to visit other cities in > alphabetical order" > Jan is correct; the characterization of a problem hinges on accurately describing what you expect and what happened instead. Terms such as

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread C Banning
https://play.golang.org/p/Pqd0Wk-yqe -- 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+unsubscr...@googlegroups.com. For more options, visit https://gr

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Valentin Deleplace
I did explain the expected result : "and I want to visit other cities in alphabetical order" Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com> a écrit : > On Wed, Mar 8, 2017 at 2:10 PM Val wrote: > > > What do you think? > > You should explain what you've expected to get instead of what yo

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Jan Mercl
On Wed, Mar 8, 2017 at 2:10 PM Val wrote: > What do you think? You should explain what you've expected to get instead of what you've got. Without that, I for one, cannot figure out what you see as broken and I have no idea why do you think it's not a good idea to sort a slice of a slice. After a

[go-nuts] sort.Slice arguments

2017-03-08 Thread Val
Hello fellows The following code (playground ) : // // I am in Philadelphia, and I want to visit other cities // itinerary := []string{"Philadelphia", "Chicago", "Boston", "Austin"} // // I am in Philadelphia, and I want to visit other