summary refs log blame commit diff stats
path: root/lexical/sort.go
blob: 5ad27f2aadf1d92d3d1adea7fc95d88f12da09fb (plain) (tree)


















                                                              
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
}