Skip to content

Instantly share code, notes, and snippets.

@xgrommx
Forked from ybigus/frequency.hs
Created August 30, 2017 13:01
Show Gist options
  • Save xgrommx/71cba20705d1bfbe4bdb156a5e22a281 to your computer and use it in GitHub Desktop.
Save xgrommx/71cba20705d1bfbe4bdb156a5e22a281 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