tracks/nim/exercises/word-count/example.nim in trackler-2.2.1.132 vs tracks/nim/exercises/word-count/example.nim in trackler-2.2.1.133
- old
+ new
@@ -4,14 +4,16 @@
type TWordCount* = CritBitTree[int]
## A mapping from strings (`words`) to ints (`counts`).
iterator words(s: string): string =
for word in s.split(AllChars - Letters - Digits - {'\0'}):
- yield toLower(word)
+ yield toLowerAscii(word)
proc wordCount*(s: string): TWordCount {.noSideEffect.} =
## Returns a mapping from the words (alphanumeric sequences) in `s` to their
## respective counts.
for word in words(s):
+ if word.len == 0:
+ continue
if not result.hasKey(word):
result[word] = 0
result[word] = result[word] + 1