Skip to content

Instantly share code, notes, and snippets.

@ybigus
Created April 14, 2017 07:23
Show Gist options
  • Save ybigus/af170bb51fd928d149b1dc9144658d74 to your computer and use it in GitHub Desktop.
Save ybigus/af170bb51fd928d149b1dc9144658d74 to your computer and use it in GitHub Desktop.
frequency
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