diff options
Diffstat (limited to 'lexical/sort.go')
-rw-r--r-- | lexical/sort.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lexical/sort.go b/lexical/sort.go new file mode 100644 index 0000000..5ad27f2 --- /dev/null +++ b/lexical/sort.go @@ -0,0 +1,19 @@ +package lexical + +import "sort" + +// Sort takes a string as input and returns the lexical order. +func Sort(word string) (sorted string) { + // Convert the string to []rune. + var r []rune + for _, char := range word { + r = append(r, char) + } + + sort.Slice(r, func(i, j int) bool { + return r[i] < r[j] + }) + + sorted = string(r) + return +} |