Blocs, procs et lambdas. Ex 8/21


#1



Blocs, procs et lambdas.


I don't understand what's wrong in my code.


groupe_1 = [4.1, 5.5, 3.2, 3.3, 6.1, 3.9, 4.7]
groupe_2 = [7.0, 3.8, 6.2, 6.1, 4.4, 4.9, 3.0]
groupe_3 = [5.5, 5.1, 3.9, 4.3, 4.9, 3.2, 3.2]
assez_grand = proc.new do |hauteur| 
h >= 4 
autorisation1 = groupe_1.select(&assez_grand)
autorisation2 = groupe_2.select(&assez_grand)
autorisation3 = groupe_3.select(&assez_grand)
end
  
**Oups, merci de réessayer. Il semble que assez_grand n'est pas une proc.**



#2

You didn't complete this new Proc.

You should add two more.

Sorry I don't understand your language quite well but you should have this:

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 do |group_1| group_1 >= 4 end
over_4_feet = Proc.new do |group_2| group_2 >= 4 end
over_4_feet = Proc.new do |group_3| group_3 >= 4 end

# 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)

Hope this helps! :smile:


#3

Hello.
Thank you but we have to write the Proc.new in one line.
Sorry but i have always the same error message :
" It seems assez grand is not a proc".


#4

Pls post your well formatted code here!

Thank you. :smile:


#5

This is my code :

groupe_1 = [4.1, 5.5, 3.2, 3.3, 6.1, 3.9, 4.7]
groupe_2 = [7.0, 3.8, 6.2, 6.1, 4.4, 4.9, 3.0]
groupe_3 = [5.5, 5.1, 3.9, 4.3, 4.9, 3.2, 3.2]
assez_grand = proc.new do |hauteur|
hauteur >= 4
end
peut_monter_1 = groupe_1.select(&assez_grand)
peut_monter_2 = groupe_2.select(&assez_grand)
peut_monter_3 = groupe_3.select(&assez_grand)

In the editor there is : tried to create Proc object without a block
And the error message is it seems "assez_grand" is not a proc.


#6

Okay still following what I said before but it's Proc.new and not proc.new. It's case sensitive.

Please follow previous suggestions also.

Hope this resolves now! :smile:


#7

Oh yes !
What a stupid error !
Thank you for your help.
I have to need more vigilant.:sunglasses:


#8

Lol! You're welcome.

Have fun coding! :smile:


#9

Your code should look like this:

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

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)


#10

You defined |hauteur| so use hauteur >=4
There's no reason to use h>=4 when you haven't defined "h" anywhere in your proc and also use Proc.new instead of proc.new
There's a difference


#11

Thank you for your response.
Happy coding.