8. Why Procs?

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/ruby-beginner-en-L3ZCI/1/3?curriculum_id=5059f8619189a5000201fbcb#

<In what way does your code behave incorrectly? Include ALL error messages.>
How can I print the first two groups as well? It only prints the last group. I appreciate your help

```

Here at the amusement park, you have to be four feet tall

or taller to ride the roller coaster. Let’s use .select on

each group to get only the ones four feet tall or taller.

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 { |height| height >= 4 }

Change these three so that they use your new over_4_feet Proc

can_ride_1 = group_1.select { |height| height >= 4 }
can_ride_2 = group_2.select { |height| height >= 4 }
can_ride_3 = group_3.select { |height| height >= 4 }

<do not remove the three backticks above>

@elderaranda,

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 { |height| height >= 4  }


# Change these three so that they use your new over_4_feet Proc
[group_1.select(&over_4_feet)].each { |cel|
  puts cel.join(" ")
}
[group_2.select(&over_4_feet)].each { |cel|
  puts cel.join(" ")
}
[group_3.select(&over_4_feet)].each { |cel|
  puts cel.join(" ")
}
puts "== or use =="
(1..3).each { |nr|
  [eval("group_"+nr.to_s).select(&over_4_feet)].each { |cel|
     puts cel.join(" ")
  }
}

Reference::
http://stackoverflow.com/questions/9726787/printing-an-array-of-arrays-on-one-line-in-console-one-line-per-master-array-ob
http://stackoverflow.com/questions/1347570/how-do-i-create-a-reusable-block-proc-lambda-in-ruby

Thank you Sir. I’ll get back to the article you sent me as soon as I can, however, I have this most recent problem that you want to view here.

https://discuss.codecademy.com/t/passing-your-lambda-to-a-method/49883

I think I got the code, there was nothing wrong with it, as far as I know, but I get this error "
Oops, try again. Did you create a variable called a_to_m?"

“(ruby):12: syntax error, unexpected tAMPER
a_to_m = crew.select (&first_half)”

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.