Hi,
sorted := sortSliceIsSorted(indexes, func(i, j int) bool {
return rantings[indexes[i]] < rantings[indexes[j]]
})
fmt.Println("Slice sorted?:", sorted)
El jueves, 9 de noviembre de 2017, 9:36:47 (UTC-3), gaurav escribió:
>
> I realized the mistake :-p
> It needs to be this:
>
> sort.Slice(indexes, func(i, j int) bool {
> return ratings[indexes[i]] < ratings[indexes[j]]
> })
>
>
> On Thursday, November 9, 2017 at 6:02:29 PM UTC+5:30, gaurav wrote:
>>
>> Hi Jan,
>>
>> I am still unable to understand why is the contract broken? The
>> "magnitude" of each entry in "indexes" slice is defined by less func in a
>> consistent way. What exactly am I doing incorrect here? If I changed the
>> program to create structs
>>
>> type entry struct {
>> rating int
>> index int
>> }
>>
>> And then create slice of these structs and defined less() based on
>> rating, would it change anything conceptually?
>>
>> On Thu, Nov 9, 2017 at 5:54 PM, Jan Mercl <[email protected] <javascript:>
>> > wrote:
>>
>>> On Thu, Nov 9, 2017 at 1:17 PM gaurav <[email protected]
>>> <javascript:>> wrote:
>>>
>>> > I must be missing something basic here: a simple usage of sort.Slice
>>> is not sorting the slice correctly for me. I must be missing something very
>>> basic here; could someone please check this out?
>>>
>>> The less test is perfomed on the ratings slice, but the item swap is
>>> perfomed on the indexes slice. This breaks the contract of SortSlice and it
>>> cannot work.
>>>
>>> --
>>>
>>> -j
>>>
>>
>>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.