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

Version Path
trackler-2.2.1.180 tracks/go/exercises/anagram/example.go
trackler-2.2.1.179 tracks/go/exercises/anagram/example.go
trackler-2.2.1.178 tracks/go/exercises/anagram/example.go
trackler-2.2.1.177 tracks/go/exercises/anagram/example.go
trackler-2.2.1.176 tracks/go/exercises/anagram/example.go
trackler-2.2.1.175 tracks/go/exercises/anagram/example.go
trackler-2.2.1.174 tracks/go/exercises/anagram/example.go
trackler-2.2.1.173 tracks/go/exercises/anagram/example.go
trackler-2.2.1.172 tracks/go/exercises/anagram/example.go
trackler-2.2.1.171 tracks/go/exercises/anagram/example.go
trackler-2.2.1.170 tracks/go/exercises/anagram/example.go
trackler-2.2.1.169 tracks/go/exercises/anagram/example.go
trackler-2.2.1.167 tracks/go/exercises/anagram/example.go
trackler-2.2.1.166 tracks/go/exercises/anagram/example.go
trackler-2.2.1.165 tracks/go/exercises/anagram/example.go
trackler-2.2.1.164 tracks/go/exercises/anagram/example.go
trackler-2.2.1.163 tracks/go/exercises/anagram/example.go
trackler-2.2.1.162 tracks/go/exercises/anagram/example.go
trackler-2.2.1.161 tracks/go/exercises/anagram/example.go
trackler-2.2.1.160 tracks/go/exercises/anagram/example.go