Skip to content

Commit

Permalink
add MapKeys method (#32)
Browse files Browse the repository at this point in the history
* add MapKeys method

* fix unit test
  • Loading branch information
zreigz authored May 13, 2024
1 parent f366b7b commit ce04ead
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions algorithms/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ func MapValues[K comparable, V any](m map[K]V) []V {
return s
}

func MapKeys[K comparable, V any](m map[K]V) []K {
s := make([]K, 0, len(m))
for k := range m {
s = append(s, k)
}
return s
}

func Merge(maps ...map[string]interface{}) map[string]interface{} {
res := maps[0]
for _, m := range maps[1:] {
Expand Down

0 comments on commit ce04ead

Please sign in to comment.