Logo

Programming-Idioms

History of Idiom 100 > diff from v35 to v36

Edit summary for version 36 by programming-idioms.org:
New Go implementation by user [programming-idioms.org]

Version 35

2016-12-18, 02:50:32

Version 36

2017-02-23, 12:17:05

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.

Extra Keywords
list
Extra Keywords
list
Imports
import "sort"
Code
sort.Slice(items, func(i, j int) bool {
	return c(items[i], items[j])
})
Comments bubble
Since Go 1.8, a single func parameter is sufficient to sort a slice.
Doc URL
https://golang.org/pkg/sort/#Slice
Demo URL
https://play.golang.org/p/WHs1vflm6v