Skip to content

Commit 80c09f6

Browse files
committed
[Add] word_count example
1 parent 05f752d commit 80c09f6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

word_count.exs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filename = IO.gets("File to count the words from: ") |> String.trim
2+
body = File.read! filename
3+
empty = fn x -> x != "" end
4+
count = String.split(body, ~r{(\\n|[^\w'])+})
5+
|> Enum.filter(empty)
6+
|> Enum.count
7+
8+
IO.puts count

0 commit comments

Comments
 (0)