History of Idiom 100 > diff from v28 to v29
Edit summary for version 29 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 28
2016-12-11, 20:22:39
Version 29
2016-12-11, 20:24:08
Idiom #100 Sort by a comparator
Sort elements of array-like collection items, using a comparator c.
Idiom #100 Sort by a comparator
Sort elements of array-like collection items, using a comparator c.
Code
type ItemCSorter []Item
func (this ItemCSorter) Len() int { return len(this) }
func (this ItemCSorter) Less(i, j int) bool { return c(this[i], this[j]) }
func (this ItemCSorter) Swap(i, j int) { this[i], this[j] = this[j], this[i] }
func sortItems(items []Item) {
sorter := ItemCSorter(items)
sort.Sort(sorter)
}
Comments bubble
Comments bubble