File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,6 +154,11 @@ concepts:
154154 test_regex : " .*"
155155 hints :
156156 - Use `sync.Mutex` to synchronize access to a shared resource.
157+ - slug : 32_sorting
158+ title : Sorting
159+ test_regex : " .*"
160+ hints :
161+ - Use `slice.Sort` for sorting slices.
157162- slug : 33_string_formatting
158163 title : String Formatting
159164 test_regex : " .*"
Original file line number Diff line number Diff line change 1+ package sorting
2+
3+ import (
4+ "slices"
5+ )
6+
7+ var Years = []int {2017 , 2003 , 2026 }
8+ var Pets = []string {"Dog" , "Cat" , "Parrot" }
9+
10+ func SortYears () []int {
11+ slices .Sort (Years )
12+ return Years
13+ }
14+
15+ func SortPets () []string {
16+ slices .Sort (Pets )
17+ return Pets
18+ }
Original file line number Diff line number Diff line change 1+ package sorting
2+
3+ var Years = []int {2017 , 2003 , 2026 }
4+ var Pets = []string {"Dog" , "Cat" , "Parrot" }
5+
6+ // TODO: Sort years before returning
7+ func SortYears () []int {
8+ return Years
9+ }
10+
11+ // TODO: Sort pets before returning
12+ func SortPets () []string {
13+ return Pets
14+ }
Original file line number Diff line number Diff line change 1+ package sorting
2+
3+ import (
4+ "slices"
5+ "testing"
6+ )
7+
8+ func TestSorting (t * testing.T ) {
9+ t .Run ("Sorting numbers" , func (t * testing.T ) {
10+ SortYears ()
11+ if ! slices .IsSorted (Years ) {
12+ t .Fatal ("Years are not sorted!" )
13+ }
14+ })
15+
16+ t .Run ("Sorting strings" , func (t * testing.T ) {
17+ SortPets ()
18+ if ! slices .IsSorted (Pets ) {
19+ t .Fatal ("Pets are not sorted!" )
20+ }
21+ })
22+ }
You can’t perform that action at this time.
0 commit comments