Guest User

Untitled

a guest
Oct 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.17 KB | None | 0 0
  1. def remove_consecutive_duplicates(xs)
  2. [xs.first] + xs.each_cons(2).select do |x,y|
  3. x != y
  4. end.map(&:last)
  5. end
  6.  
  7. remove_consecutive_duplicates([1, 2, 2, 3, 1])
  8. #=> [1,2,3,1]
Add Comment
Please, Sign In to add comment