Go Back   CodingForums.com > :: Server side development > Ruby & Ruby On Rails

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-30-2012, 11:07 AM   PM User | #1
gibsonguy
New to the CF scene

 
Join Date: Jul 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
gibsonguy is an unknown quantity at this point
Method explanation?

Hi,
Just wondering if anyone can help me decipher this method? I know it creates an empty array and while its empty push a value into it as long as that value equals the input? The second part - I think pushes values to the array and deletes the last value in it?

Thanks

[code

def explain_me(inputs)
my_array = []
while !inputs.empty?
value = inputs[0]
inputs.each do | input |
if input < value
value = input
end
end
my_array.push value
inputs.delete value
end
return my_array
end

/code]
gibsonguy is offline   Reply With Quote
Old 09-03-2012, 10:01 AM   PM User | #2
webmiral
New Coder

 
Join Date: Sep 2012
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
webmiral is an unknown quantity at this point
See the comments

Here is the description on the code

Code:
def explain_me(inputs)
  my_array = []
  while !inputs.empty? # while has any item on inputs array
    value = inputs[0] # put the first itom of inputs array into value variable
    inputs.each do | input | # this loop find the lowest value of inputs array
      if input < value
        value = input
      end
    end # now value is the lowest value of the inputs items
    my_array.push value # this lowest value is putting into my_array
      inputs.delete value # and deleted from input array
    end
    return my_array # return my array
end # def explain_me
Do you see?

Have a nice day.
webmiral is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:15 AM.


Advertisement
Log in to turn off these ads.