Sha256: 310f8633ffffbe90e8b0e7dc31845efdc57389f468a68f516bd540d4667f3bf4

Contents?: true

Size: 564 Bytes

Versions: 27

Compression:

Stored size: 564 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 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

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.158 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.157 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.156 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.155 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.154 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.153 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.152 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.151 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.150 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.149 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.148 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.147 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.146 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.145 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.144 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.143 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.142 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.141 tracks/nim/exercises/word-count/example.nim
trackler-2.2.1.140 tracks/nim/exercises/word-count/example.nim