Quidest?

Sorting a slice in Go

ยท Lorenzo Drumond

A slice is an ordered collection of elements. A map is a random collection of elements. This means that when we want to compare the elements of a map (not the keys) agains a slice, we should make sure that both are sorted to avoid errors due to the fact that map is not ordered.

We can use the slice.Slice function, which takes a slice, and a comparison function that explains how any two elements of the slice should be ordered; this functions will order the slice in place.

References

#programming #nil #map #struct #golang #element