8. Why Procs? Strange results


#1

I'm working on this and have the following:

group_1=[4.1, 5.5, 3.2, 3.3, 6.1, 3.9, 4.7]
group_2=[7.0, 3.8, 6.2, 6.1, 4.4, 4.9, 3.0]
group_3=[5.5, 5.1, 3.9, 4.3, 4.9, 3.2, 3.2]

over_4_feet=Proc.new {|height|height>=4}

group_1 = group_1.select(&over_4_feet)
group_2 = group_2.select(&over_4_feet)
group_3 = group_3.select(&over_4_feet)

However, although it passes it gives the following result:

[5.5, 5.1, 4.3, 4.9]

So there are results missing. Can anyone help me work out what I've done wrong please? I'm sure it's something obvious but I can't work out what. Thanks for your help


#2

Hello,

There are no results missing, ruby will display the last block evaluated by default, in this case: group_3 = group_3.select(&over_4_feet) => [5.5, 5.1, 4.3, 4.9]

It does not print group_1 and group_2 because you didn't code it this way, if you want ruby to print the result for each group, use puts or print.

I hope this was helpful as i'm a beginner too and as you may have noticed, english isn't my mother tongue :slightly_smiling:

Feel free to ask for more explanation if it isn't clear.