20. Creating a Lambda


#1

I am going absolutely mental trying to figure out what is wrong with my code. I feel like I am doing exactly what I'm asked for this section but whenever I submit I am told "Oops, try again. Make sure to put your capital M in quotes, like this: 'M'". Can anyone shine some light on this?

crew = {
  captain: "Picard",
  first_officer: "Riker",
  lt_cdr: "Data",
  lt: "Worf",
  ensign: "Ro",
  counselor: "Troi",
  chief_engineer: "LaForge",
  doctor: "Crusher"
}

first_half = lambda {|k,v| k < "M"}

#2

So obviously as soon as I posted this I figured it out. It's testing the value, not the key. So this works:

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 {|k,v| v < 'M'}

#3

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 = crew.select{ |k, v| }
if ( "v" <= "M" )

puts crew.select(&first_half)
end

This worked for me, but I don't know why or how.


#4

I see why now, it was easy and I did the puts section actually ahead of the next task. Hmm.


#5

I did the exact same thing. Thanks. :relaxed:


#6

that is very good and very simple.
i'm right with it code