History of Idiom 28 > diff from v32 to v33
Edit summary for version 33 by programming-idioms.org:
[Go] this is not an idiomatic name, choosing s instead.
[Go] this is not an idiomatic name, choosing s instead.
↷
Version 32
2016-12-11, 20:41:40
Version 33
2016-12-11, 20:45:09
Idiom #28 Sort by a property
Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.
Idiom #28 Sort by a property
Sort elements of array-like collection items in ascending order of x.p, where p is a field of the type Item of the objects in items.
Code
type ItemPSorter []Item
func (this ItemPSorter) Len() int{ return len(this) }
func (this ItemPSorter) Less(i,j int) bool{ return this[i].p<this[j].p }
func (this ItemPSorter) Swap(i,j int) { this[i],this[j] = this[j],this[i] }
func sortItems(items []Item){
sorter := ItemPSorter(items)
sort.Sort( sorter )
}
Comments bubble
Comments bubble