Returns a map with the unique values of the collection as keys and their frequencies as the values.

Implement an appropriate function for each type.
Use make() to create a map.
Use range to iterate over the elements in the collection, adding to existing keys every time the same value is encountered.

继续阅读 30秒学会 Golang 片段 – Frequencies

Deduplicates the elements in a given array or slice.

Implement an appropriate function for each type.
Use make() to create a map and an appropriate slice.
Use range to iterate over the elements in the collection and the map to check if they have been seen before.
Use append() to add unique values to the slice.

继续阅读 30秒学会 Golang 片段 – Dedupe