Skip to content

Instantly share code, notes, and snippets.

@thanhpp
Created January 25, 2022 07:29
Show Gist options
  • Save thanhpp/1610c7f7a185579886fa7880e2ebbe41 to your computer and use it in GitHub Desktop.
Save thanhpp/1610c7f7a185579886fa7880e2ebbe41 to your computer and use it in GitHub Desktop.
teko_test1.go
package main
import (
"fmt"
"sort"
)
func main() {
var (
req = []string{"812", "82", "7", "23", "12", "34"}
)
sort.Slice(req, func(a, b int) bool {
return req[a] == min(req[a], req[b])
})
fmt.Println(req)
for i := 0; i < len(req); i++ {
fmt.Print(req[len(req)-i-1])
}
}
func min(a, b string) string {
var (
minLength int
)
if len(a) < len(b) {
minLength = len(a)
} else {
minLength = len(b)
}
for i := 0; i < minLength; i++ {
if a[i] < b[i] {
return a
}
if a[i] > b[i] {
return b
}
}
if len(a) < len(b) {
return a
}
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment