LoginSignup
4
2

More than 3 years have passed since last update.

Goでint64配列をソートする

Last updated at Posted at 2018-05-21

int配列はsort.Ints()でソート出来るけど、int64はどうやるんだろう?と調べたらsort.Slice()で出来たのでメモしておく。

slice_sample.go
package main

import (
    "fmt"
    "sort"
)

func main() {
    ids := []int64{
        3, 4, 5, 2, 1,
    }

    // 昇順ソート
    sort.Slice(ids, func(i, j int) bool {
        return ids[i] < ids[j]
    })

    // [1 2 3 4 5]
    fmt.Println(ids)
}
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2