From ffafafa2393479027ccff4ff86ba31aaaf9a1661 Mon Sep 17 00:00:00 2001 From: flaviut Date: Thu, 17 Jul 2014 13:29:09 -0400 Subject: [PATCH] Use count tables for centerpiece example --- content/index.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/content/index.md b/content/index.md index 32818f0..3f7a287 100644 --- a/content/index.md +++ b/content/index.md @@ -11,18 +11,11 @@ Getting started? Head over to the [installation instructions](/getting_started/) ``` nimrod import tables, strutils -var wordFrequencies = initTable[string, int]() +var wordFrequencies = newCountTable[string]() for line in stdin.lines: for word in line.split(", "): - wordFrequencies[word] = wordFrequencies[word] + 1 + wordFrequencies.inc(word) -var maxFrequency = 0 -var mostFrequentWord: string -for word, frequency in wordFrequencies: - if frequency > maxFrequency: - maxFrequency = frequency - mostFrequentWord = word - -echo "The most frequent word is '", mostFrequentWord, "'" +echo "The most frequent word is '", wordFrequencies.largest, "'" ``` \ No newline at end of file