underscore/docs/content/collections/groupby.md
2024-09-08 19:11:52 +02:00

414 B

title date
Group by 2023-06-07T00:49:56+02:00

GroupBy splits a slice into a map[K][]V grouped by the result of the iterator function.

package main

import (
 "fmt"
 u "github.com/rjNemo/underscore"
)

func main() {
   nums := []float64{1.3, 2.1, 2.4}
 groupingFunc := func(n float64) int { return int(math.Floor(n)) }
   res := u.GroupBy(nums, groupingFunc) // { 1: {1.3}, 2: {2.1, 2.4}}
}