Created
September 28, 2011 18:35
-
-
Save invisiblefunnel/1248809 to your computer and use it in GitHub Desktop.
Remove sequential duplicates recursively
This file contains 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
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