Closed rasa closed 2 months ago
We cannot find a general algorithm for all SDKs in sorting beta or rc versions.
And also it hardly matters, as the disorder is very tiny.
It isn’t worth the trouble.
@moqsien https://go.dev/play/p/Z0BNYudoRPj
package main
import (
"fmt"
"go/version"
"slices"
)
func main() {
vers := []string{
"go1.23rc2",
"go1.23rc1",
"go1.23.0",
"go1.22rc2",
"go1.22rc1",
"go1.22.1",
"go1.22.0",
"go1.21.13",
}
slices.SortFunc(vers, func(a, b string) int {
return version.Compare(a, b)
})
fmt.Printf("%v\n", vers)
}
[go1.21.13 go1.22rc1 go1.22rc2 go1.22.0 go1.22.1 go1.23rc1 go1.23rc2 go1.23.0]
So, how about JDK, Python, Nodejs, bun, gcc, clang, kotlin, scala, etc?
Note that, we are not only for go.
So, how about JDK, Python, Nodejs, bun, gcc, clang, kotlin, scala, etc?
Note that, we are not only for go.
Understood. We would need to prefix "go" to the versions, sort, then remove the prefix.
I will provide a PR, if you point to where in the code we would add this.
Or perhaps we use https://pkg.go.dev/golang.org/x/mod/semver#Compare instead?
Numeric suffixes sort ok:
But alphanumeric suffixes don't:
This would be preferable: