Sha256: eed439bdc9af01202db7f543d75cba79fcb2e919c5f857de141159d2d6c119f0
Contents?: true
Size: 559 Bytes
Versions: 122
Compression:
Stored size: 559 Bytes
Contents
package anagram import ( "sort" "strings" ) 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
122 entries across 122 versions & 1 rubygems