How do you merge consecutive repeating elements in an array?

后端 未结 4 1774
[愿得一人]
[愿得一人] 2020-12-20 17:26

I need to merge consecutive repeating elements in an array, such that

[1, 2, 2, 3, 1]

becomes

[1, 2, 3, 1]
<
4条回答
  •  一个人的身影
    2020-12-20 18:09

    does !uniq not work for what you are doing?

    http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_array.html

提交回复
热议问题