mirror of
https://github.com/cheat/cheat.git
synced 2025-12-26 17:02:06 +01:00
Re-wrote from scratch in Golang
- Re-implemented the project in Golang, and deprecated Python entirely - Implemented several new, long-requested features - Refactored cheatsheets into a separate repository
This commit is contained in:
32
internal/sheets/sort.go
Normal file
32
internal/sheets/sort.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user