1
votes

I appreciate there are many already mentioned methods on Stack that you can use to find the lowest value integer, but the majority seem to be based on arrays and inbuilt ruby methods. I am tasked with finding the lowest value integer in a hash value by using flow control only. I have tried and researched multiple ways of doing this via iteration etc, and I have hit the brick wall! I need to do all of this inside of my increase method. My current code:

class Class
  def initialize(object)
    @object = object
  end
  
  def increase
    @object
  end
end

class = Class.new({first_key: 350, second_key: 200})
1
What is the expected output? 200? Or :second_key? Or {second_key: 200}spickermann
Is this a homework assignment?Casper
Sorry! The expected output is to find the value which is lowest and increase the value by a given amount...eg. increase second_key's value by 10..so return would be 210. I understand I could do: '$least_amount = @object.sort_by { |k, v| v }.first[1]' and then do '$least_amount += 10' but i need to be able to do it via flow control only. Im starting to twonder if it is even possible but maybe its my inexperience!?AlwaysBetOnBlack

1 Answers

0
votes
{ a: 2, b: 1, c: 3 }.min_by(&:last).last + 10
# => 11

{ a: 2, b: 1, c: 3 }.values.min + 10
# => 11