There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hi, yes! I’m getting the same and my code looks exactly like the one that the “Solution” posted. I keep getting a question saying "Did you put a “Proc.new” block. even though i have. I’ve also tried to change “puts” into “print” like mtf replied but that didn’t do anything. Also, in the Solution, puts stayed as puts. I’m getting a syntax error in the console for all three can_ride_ groups.
the image is my code
I was doing this excercise, but I still don’t get the need for proc as the problem is perfetly solvable with method as well … See the method test I have written to copy functionality of proc
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]
# Complete this as a new Proc
over_4_feet = Proc.new {
|h| h >= 4
}
# this one is using a method and it work perfetly, why is ther a need for proc?
def test(h)
return h >= 4
end
can_ride_1 = group_1.select { |x| test(x) }
# Change these three so that they use your new over_4_feet Proc
can_ride_1 = group_1.select(&over_4_feet)
can_ride_2 = group_2.select(&over_4_feet)
can_ride_3 = group_3.select(&over_4_feet)
puts can_ride_1
puts can_ride_2
puts can_ride_3
Although we would miss the demonstration of assignment, you make a good point. When the variable is never going to be used more than the one time, it is better memory management to print the expression, directly.