[英]Loop through array and delete all duplicates in ruby
I need to loop through an array called @ads and delete all objects in it that are duplicates of one another. 我需要遍历一个称为@ads的数组,并删除其中的所有重复对象。 how do i do this? 我该怎么做呢?
@ads = @ads.uniq
要么
@ads.uniq!
下面的代码将通过id给您唯一的结果。
@ads = @ads.uniq{|ad| ad.id}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.