MCPcopy Index your code
hub / github.com/cheat/cheat / Sort

Function Sort

internal/sheets/sort.go:10–32  ·  view source on GitHub ↗

Sort organizes the cheatsheets into an alphabetically-sorted slice

(cheatsheets map[string]sheet.Sheet)

Source from the content-addressed store, hash-verified

8
9// Sort organizes the cheatsheets into an alphabetically-sorted slice
10func Sort(cheatsheets map[string]sheet.Sheet) []sheet.Sheet {
11
12 // create a slice that contains the cheatsheet titles
13 var titles []string
14 for title := range cheatsheets {
15 titles = append(titles, title)
16 }
17
18 // sort the slice of titles
19 sort.Strings(titles)
20
21 // create a slice of sorted cheatsheets
22 sorted := []sheet.Sheet{}
23
24 // iterate over the sorted slice of titles, and append cheatsheets to
25 // `sorted` in an identical (alabetically sequential) order
26 for _, title := range titles {
27 sorted = append(sorted, cheatsheets[title])
28 }
29
30 // return the sorted slice of cheatsheets
31 return sorted
32}

Callers 2

cmdSearchFunction · 0.92
TestSortFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSortFunction · 0.68