Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort should add SliceStable #73

Open
AlphaWong opened this issue Oct 19, 2019 · 0 comments
Open

Sort should add SliceStable #73

AlphaWong opened this issue Oct 19, 2019 · 0 comments

Comments

@AlphaWong
Copy link

Hi,

I think about the sort section should have SliceStable

reference

https://golang.org/pkg/sort/#SliceStable

e.g.

family := []struct {
    Name string
    Age  int
}{
    {"Alice", 23},
    {"David", 2},
    {"Eve", 2},
    {"Bob", 25},
}

// Sort by age, keeping original order or equal elements.
sort.SliceStable(family, func(i, j int) bool {
    return family[i].Age < family[j].Age
})
fmt.Println(family) // [{David 2} {Eve 2} {Alice 23} {Bob 25}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant