Im trying to figure out how to create a new开发者_如何学C list that has only the elements that occur only once. I can't use recursion either.
This is a small part of a bigger function. Im trying to write a function to get the Intersect of two sets. Basically i combined the sets. Then sorted. Then i want to combine that with set B and get rid of all the duplicates in that set. Unless someone else knows an easier way.
I can use high order functions, but i can't use recursion.
Thanks
Edit: Example:
[1,2,3,3,4,4,5,5] Should come out as [1,2]
This question was already asked before and essentially you just want to group them together by counting the number of elements and then only extracting those with a count of one. (probably using 'filter')
Please see Counting unique elements in a list
I hope this hint is sufficiently vague. :)
Think about grouping duplicate elements together.
Think about what data structure you'd use to keep track of how many times each thing shows up.
How about:
concat $ filter (null . tail) $ group [1,2,3,3,4,4,5,5]
精彩评论