simple-exercises/ruby-exercises/easy-8.rb
# Price is Right
# ------------------------------------------------------------------------------
# Given a list of bids and an actual retail price, return the bid that is closest
# to the actual retail price without going over that price.
#
# Assume there is always at least one bid below the retail price.
Price is Right
Given a list of bids and an actual retail price, return the bid that is closest
to the actual retail price without going over that price.

Assume there is always at least one bid below the retail price.
Price is Right Given a list of bids and an actual retail price return the bid that is closest to the actual retail price without going over that price . Assume there is always at least one bid below the retail price .
def price_is_right(bids, actual_retail_price)
  best_bid = nil
  smallest_diff = nil
  bids.each do |bid|
    diff = actual_retail_price - bid
    if diff > 0
      if best_bid == nil or smallest_diff > diff
        smallest_diff = diff
        best_bid = bid
      end
    end
  end
  best_bid
end
def price_is_right ( bids , actual_retail_price ) best_bid = nil smallest_diff = nil bids . each do | bid | diff = actual_retail_price - bid if diff > 0 if best_bid == nil or smallest_diff > diff smallest_diff = diff best_bid = bid end end end best_bid end
Price is Right
Given a list of bids and an actual retail price, return the bid that is closest
to the actual retail price without going over that price.
Price is Right Given a list of bids and an actual retail price return the bid that is closest to the actual retail price without going over that price .
bids
<not_specific>
actual_retail_price
<not_specific>