mirror of
https://github.com/cheat/cheat.git
synced 2024-11-22 14:01:36 +01:00
e5114a3e76
- Re-implemented the project in Golang, and deprecated Python entirely - Implemented several new, long-requested features - Refactored cheatsheets into a separate repository
33 lines
753 B
Go
33 lines
753 B
Go
package sheets
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/cheat/cheat/internal/sheet"
|
|
)
|
|
|
|
// Sort organizes the cheatsheets into an alphabetically-sorted slice
|
|
func Sort(cheatsheets map[string]sheet.Sheet) []sheet.Sheet {
|
|
|
|
// create a slice that contains the cheatsheet titles
|
|
var titles []string
|
|
for title := range cheatsheets {
|
|
titles = append(titles, title)
|
|
}
|
|
|
|
// sort the slice of titles
|
|
sort.Strings(titles)
|
|
|
|
// create a slice of sorted cheatsheets
|
|
sorted := []sheet.Sheet{}
|
|
|
|
// iterate over the sorted slice of titles, and append cheatsheets to
|
|
// `sorted` in an identical (alabetically sequential) order
|
|
for _, title := range titles {
|
|
sorted = append(sorted, cheatsheets[title])
|
|
}
|
|
|
|
// return the sorted slice of cheatsheets
|
|
return sorted
|
|
}
|