Skip to content

Instantly share code, notes, and snippets.

@invisiblefunnel
Created September 28, 2011 18:35
Show Gist options
  • Save invisiblefunnel/1248809 to your computer and use it in GitHub Desktop.
Save invisiblefunnel/1248809 to your computer and use it in GitHub Desktop.
Remove sequential duplicates recursively
def destutter list
if list.length < 2
list
else
a = list.shift
a == list[0] ?
destutter(list) :
destutter(list).unshift(a)
end
end
## Example usage
p destutter([0,"x","x",{foo:"bar"},{foo:"bar"},1,1,2,2,3,3,4,4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment