Created
April 14, 2017 07:23
-
-
Save ybigus/af170bb51fd928d149b1dc9144658d74 to your computer and use it in GitHub Desktop.
frequency
This file contains hidden or 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
count:: Int -> [Int] -> Int | |
count x arr = length $ filter (\i -> i == x) arr | |
freq:: [Int] -> [Int] -> [(Int, Int)] | |
freq [] _ = [] | |
freq (x:xs) acc = [(x, count x acc + 1)] ++ freq xs (x: acc) | |
example:: [(Int, Int)] | |
example = freq [1,2,1,2,4,2,1] [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment