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.2.1.132 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.131 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.130 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.129 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.128 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.127 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.126 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.125 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.124 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.123 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.122 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.121 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.120 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.119 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.118 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.117 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.116 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.115 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.114 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.113 tracks/nim/exercises/word-count/example.nim