sort implementation




    Go Code Snippets

    func (a ) Greater(i, j int) bool { return a[i > a[j]] }

    The type SortBy is an array of Type, and the three functions Len(), Swap(), and Less() take two int arguments and return an int. The function Greater() takes an int and a int and returns a bool.

    Shortcut: sort

    type SortBy []Type
    func (a ) Len() int           { return len(a) }
    func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
    func (a ) Less(i, j int) bool { return a[i < a[j]] }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.