Sha256: 2ed120386c76b2ee7a46014909f352b0cff2c49074402efdf05ff8858e7b0f7d
Contents?: true
Size: 582 Bytes
Versions: 84
Compression:
Stored size: 582 Bytes
Contents
package anagram import ( "sort" "strings" ) const testVersion = 2 func Detect(subject string, candidates []string) []string { subject = strings.ToLower(subject) var matches []string for _, c := range candidates { if tc := strings.ToLower(c); isAnagram(subject, tc) { matches = append(matches, c) } } return matches } func isAnagram(subject, candidate string) bool { return subject != candidate && alphagram(subject) == alphagram(candidate) } func alphagram(s string) string { chars := strings.Split(s, "") sort.Strings(chars) return strings.Join(chars, "") }
Version data entries
84 entries across 84 versions & 1 rubygems