In Go:
func isAnagramOfPalindrome(str string) bool {
charCounts := map[rune]int{}
for _, c := range str {
charCounts[c]++
}
numOdd := 0
for _, count := range charCounts {
if count%2 == 1 {
numOdd++
}
}
return numOdd <= 1;
}
In this case I think I do prefer the latter. I like how I can name the intermediate objects. :)Also I don't like the practice of groupBy().map(=>_.size()), which hides the performance penalty of creating arrays. I'm sure a better compiler can do better, but I'd have to know the compiler to assume that.