![]() |
|
Navigation |
Synopsis Counting words in strings.
Examples The purpose of WordCount is to count the number of words in a list of lines (strings).
A word is here defined as one or more letters (lowercase or uppercase), digits and the underscore character (
_ ).
We split the problem in two parts:
wordCount is a function with two arguments:
wordCount is to loop over all lines and to add the word counts per line.
module demo::common::WordCount::WordCount // wordCount takes a list of strings and a count function // that is applied to each line. The total number of words is returned public int wordCount(list[str] input, int (str s) countInLine) { count = 0; for(str line <- input){At ![]() ![]() countInLine is applied to count the number of words in each line.
Let's now do some experiments using the Jabberwocky poem by Lewis Carrol as input. Explain what is going on in this function. ![]() |