Skip to content

I get repeated items #2

Description

@pmaojo
    @inserciones = Adblock.where(code: @sponsorsection).inject({}) {|h, p| h[p.id] = p.ranking; h}
    @ofertas_select2 = WeightedRandomizer.new(@inserciones) 
    @ofertas_select = @ofertas_select2.sample(3)
    @coupons = []
    @ofertas_select.each do |o|
      @insert = Adblock.find(o)
      @oferta = @insert.coupon
      if @oferta.publicada == true
        @coupons << @oferta
      end
    end

Is returning random results, and sometimes the same item is picked 3 times, there are 3 items to chose { one => 3, two => 2, three => 1}

Is there a way to avoid repeating ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions