Count occurrences of an element in a list (Answer must be in Haskell Programming language) For this
Fantastic news! We've Found the answer you've been seeking!
Question:
Count occurrences of an element in a list (Answer must be in Haskell Programming language)
For this problem, youll write a list-processing function thatconsumesa list, but just produces an integer. It should count how many times a particular element appears in a list. Here are some examples:
ghci> countOccurences 5 [1..10]
1
ghci> countOccurences 5 [1,5,2,5,3,5,7,5]
4
ghci> countOccurences 'a' "abracadabra"
5
ghci> countOccurences 'o' "xylophone"
2
You can either write it recursively by pattern-matching on the list, or you can use a combination of existing functions.
Posted Date: