Checks for Palindrome strings or numbers in Go Lang
import (
"regexp"
"strings"
)
func IsPalindromic(value string) bool {
value = sanitize(value)
for i := 0; i < len(value)/2; i++ {
if value[i] != value[len(value)-i-1] {
return false
}
}
return true
}
func sanitize(value string) string {
reg, _ := regexp.Compile("[^A-Za-z0-9]+")
safe := reg.ReplaceAllString(value, "")
return strings.ToLower(strings.Trim(safe, ""))
}
Written by Breno Martinusso
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Go
Authors
Related Tags
#go
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#