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

Version Path
trackler-2.2.1.56 tracks/go/exercises/anagram/example.go
trackler-2.2.1.55 tracks/go/exercises/anagram/example.go
trackler-2.2.1.54 tracks/go/exercises/anagram/example.go
trackler-2.2.1.53 tracks/go/exercises/anagram/example.go
trackler-2.2.1.52 tracks/go/exercises/anagram/example.go
trackler-2.2.1.51 tracks/go/exercises/anagram/example.go
trackler-2.2.1.50 tracks/go/exercises/anagram/example.go
trackler-2.2.1.49 tracks/go/exercises/anagram/example.go
trackler-2.2.1.48 tracks/go/exercises/anagram/example.go
trackler-2.2.1.47 tracks/go/exercises/anagram/example.go
trackler-2.2.1.46 tracks/go/exercises/anagram/example.go
trackler-2.2.1.45 tracks/go/exercises/anagram/example.go
trackler-2.2.1.44 tracks/go/exercises/anagram/example.go
trackler-2.2.1.43 tracks/go/exercises/anagram/example.go
trackler-2.2.1.42 tracks/go/exercises/anagram/example.go
trackler-2.2.1.41 tracks/go/exercises/anagram/example.go
trackler-2.2.1.40 tracks/go/exercises/anagram/example.go
trackler-2.2.1.39 tracks/go/exercises/anagram/example.go
trackler-2.2.1.38 tracks/go/exercises/anagram/example.go
trackler-2.2.1.37 tracks/go/exercises/anagram/example.go