Skip to content

Commit 555ea05

Browse files
committed
valid-palindrome: map function version
1 parent a19cf61 commit 555ea05

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

valid-palindrome/invidam.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
func isPalindrome(s string) bool {
2-
filtered := ""
3-
for _, ch := range s {
4-
if unicode.IsLetter(ch) || unicode.IsNumber(ch) {
5-
filtered += string(unicode.ToLower(ch))
2+
filtered := strings.Map(func(r rune) rune {
3+
if !unicode.IsLetter(r) && !unicode.IsNumber(r) {
4+
return -1
65
}
7-
}
6+
return unicode.ToLower(r)
7+
}, s)
88

99
for ldx, rdx := 0, len(filtered) - 1; ldx < rdx; ldx, rdx = ldx + 1, rdx - 1 {
1010
if filtered[ldx] != filtered[rdx] {

0 commit comments

Comments
 (0)