Last active
December 7, 2022 06:17
-
-
Save usk81/b1239fb8edf46496fe9a09fb7d68f412 to your computer and use it in GitHub Desktop.
五十音順並び替え
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sort" | |
) | |
func main() { | |
ts := []string{"あ","た","ら","し","い","ひ","び"} | |
sort.Slice(ts, func(i, j int) bool { | |
// fmt.Printf("i: %v, j:%v\n", i, j) | |
return ts[i] < ts[j] | |
}) | |
for _, t := range ts { | |
fmt.Printf(t) | |
// => あいしたひびら | |
} | |
fmt.Println("") | |
fmt.Printf("あ > ほ, expected: false, result: %v", "あ" > "ほ") | |
// => あ > ほ, expected: false, result: false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
簡単なデモ
sortのデフォルト処理だけでもUnicodeの順番でひらがなの並び替えはできるようです。
https://unicode-table.com/en/blocks/hiragana/
Go-Playground
https://play.golang.org/p/lq5SP2FvxK