Sort organizes the cheatsheets into an alphabetically-sorted slice
(cheatsheets map[string]sheet.Sheet)
| 8 | |
| 9 | // Sort organizes the cheatsheets into an alphabetically-sorted slice |
| 10 | func 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 | } |