20. Creating a lamba


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-L3ZCI/3/4?curriculum_id=5059f8619189a5000201fbcb#


Hello, I've managed to go through the exercise fine by respecting ruby codes.

When I print or puts the method I've created : first_half it's not showing the names of the people under M.

Is there something I am not understanding in Lambda ?
Thank you for your time.


crew = {
  captain: "Picard",
  first_officer: "Riker",
  lt_cdr: "Data",
  lt: "Worf",
  ensign: "Ro",
  counselor: "Troi",
  chief_engineer: "LaForge",
  doctor: "Crusher"
}
# Add your code below!
first_half = lambda { |f,n| n < "M" }

puts first_half


#2

I'm going through the exercices and starting to see how to make what I wanted to on the first place but this makes Lambda a bit confusing..


#3

Do you think it should be doing something else? If so, what?


#4

Ionatan,

First thank you for your prompt reply.

The answer I get from the code above is

"#< Proc:0x000000025069a8@(ruby):11 (lambda)>"
nil

So yes I was expecting it to show what i've called in the first_half method being showing all the names under M...


#5

Reading your output, that's a string representation of a lambda function.

What did you want to happen with the lambda function? Invoke it, right, and keep its result.
More specifically you'll want to give it to some other function which uses it to test if something should be included. If you look at your code, do you see anything matching that behavior?


#6

I actually read the exercise now (which I'm generally reluctant to do because I rarely want to help with the exercise directly, but rather with whatever is preventing people from solving it)

So back to the matter of what's expected to happen: The instructions doesn't say what should happen, perhaps that's for next exercise?

You're right about that the name first_half is misleading, since it doesn't refer to the first half of the collection. I think you just missed the part of finding out what the expected result is, and filled in the blank yourself, expecting more to happen.


#7

Yes it was for the next exercise.

I guess I was expecting to do what the next exercise ask us to do and was wondering why if I asked first_half to be printed why it wouldn't print..