// Package isogram is for determining if a word/phrase is an isogram.
package isogram
import (
"strings"
)
// IsIsogram returns true if input is an isogram, false otherwise.
func IsIsogram(input string) (ret bool) {
// Space, hyphen and mixed case does not matter
input = strings.ReplaceAll(input, " ", "")
input = strings.ReplaceAll(input, "-", "")
input = strings.ToLower(input)
// Preallocate worst case map size, this way there is no need to reallocate
// This make the code ~40-60% faster with these short words
used := make(map[rune]bool, len(input))
for _, ch := range input {
if _, found := used[ch]; found {
// this rune is already in the map
return false
}
used[ch] = true
}
return true
}