Shop.each do |shop|
if !shop.comments.blank?
n = shop.comments.length
for i in 0..n-1
for j in i+1..n-1
if shop.comments[i].content == shop.comments[j].content
shop.comments[j].destroy
end
end
end
end
end
以上为ruby冒泡算法删除店铺下的重复评论代码
Shop.each do |shop|
if !shop.comments.blank?
n = shop.comments.length
for i in 0..n-1
for j in i+1..n-1
if shop.comments[i].content == shop.comments[j].content
shop.comments[j].destroy
end
end
end
end
end
以上为ruby冒泡算法删除店铺下的重复评论代码