gibsonguy
07-30-2012, 11:07 AM
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]
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]