Skip to content

Commit d65c8c3

Browse files
authored
Merge pull request #9 from bvigar/master
sets SortByKeys bug fix
2 parents fa1e7cb + d4119df commit d65c8c3

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎sets.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ func SetMerge(a []string, b []string) []string {
6868

6969
// SortByKeys returns a new ordered slice based on the keys ordering
7070
func SortByKeys(keys []string, strs []string) []string {
71-
c := make([]string, len(strs))
71+
resultLen := len(strs)
72+
if len(keys) < len(strs) {
73+
resultLen = len(keys)
74+
}
75+
c := make([]string, resultLen)
7276

7377
index := 0
7478
Outer:

‎sets_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ func TestSortByKeys(t *testing.T) {
121121
[]string{"stuff", "thing"},
122122
[]string{"thing", "stuff"},
123123
},
124+
{
125+
[]string{"stuff"},
126+
[]string{"stuff", "thing"},
127+
[]string{"stuff"},
128+
},
124129
}
125130

126131
for i, test := range tests {

0 commit comments

Comments
 (0)