Skip to content

Commit

Permalink
Add helper to sort map keys
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M committed Feb 9, 2023
1 parent fdd9a52 commit ba76617
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/ui/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ui

import (
"sort"

"github.com/derailed/tview"
)

func SortMapByKeys(m map[string]tview.Primitive) map[string]tview.Primitive {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)

sortedMap := make(map[string]tview.Primitive, len(m))
for _, k := range keys {
sortedMap[k] = m[k]
}
return sortedMap
}

func SortMapKeys(m map[string]tview.Primitive) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

0 comments on commit ba76617

Please sign in to comment.