Last active
April 16, 2019 19:36
-
-
Save ChristophP/35d09ae04b2399ca398bcf1c7e97b167 to your computer and use it in GitHub Desktop.
count occurance of words in a sentence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module OccuranceCount where | |
import Data.Foldable (foldl') | |
countWord :: String -> String -> Int | |
countWord needle = | |
foldl' (\acc word -> if word == needle then acc + 1 else acc) 0 . words | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment