Sha256: 7f162403ee84335b680915d548073d4bd3591d0453a3806bf5a0b90e49e6d1d8

Contents?: true

Size: 522 Bytes

Versions: 349

Compression:

Stored size: 522 Bytes

Contents

import
  critbits, strutils

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)

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 not result.hasKey(word):
      result[word] = 0
    result[word] = result[word] + 1

Version data entries

349 entries across 349 versions & 1 rubygems

Version Path
trackler-2.1.0.54 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.53 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.52 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.51 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.50 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.49 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.48 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.47 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.46 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.45 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.44 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.43 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.42 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.41 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.40 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.39 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.38 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.37 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.36 tracks/nim/exercises/word-count/example.nim
trackler-2.1.0.34 tracks/nim/exercises/word-count/example.nim