14. Becoming More Selective


#1




It says " It looks like good_movies doesn't include primer, but it should!" but when I run the code it prints:
primer
the_matrix
truman_show
skyfall
lion_king


movie_ratings = {
  memento: 3,
  primer: 3.5,
  the_matrix: 5,
  truman_show: 4,
  red_dawn: 1.5,
  skyfall: 4,
  alex_cross: 2,
  uhf: 1,
  lion_king: 3.5
}
# Add your code below!

good_movies = movie_ratings.select do |m, r|  
    if r > 3
    puts m
    end
end


#2

You're not printing good_movies though, and that's what it complains about
Here's a description of how select behaves: http://ruby-doc.org/core-2.4.0/Enumerable.html#method-i-select


#3

Now I'm printing good movies but it still gives the same message.

Add your code below!

movie_ratings = {
memento: 3,
primer: 3.5,
the_matrix: 5,
truman_show: 4,
red_dawn: 1.5,
skyfall: 4,
alex_cross: 2,
uhf: 1,
lion_king: 3.5
}

good_movies = movie_ratings.select do |m, r|
if r > 3
puts m
end
end

print good_movies


#4
  • You know how to find out what's in a hash.
  • You have an error message complaining about the values in your hash.
  • You have instructions which should give you an expectation of what should be in the hash after running your code.

So what you should do is to find out what is in the hash, and compare that to your expectations.


Additionally, you've got the description of the select method which you should read very carefully and make sure that you understand how it can be used, and that you are using it that way.


You've still got much to investigate, you're not stuck. Have a look at what you've got.


#5

All I don't get is why the movies aren't in "good_movies". Can you tell me how to get them there?


#6

The idea is to call the select method and to only keep those that have a rating above 3
How can select be told to keep or discard an entry? (See that rubydoc link, the description of the method is two sentences, go read how it behaves)

A better question is also: Why would there be movies in good_movies? (Because if you ask why it isn't happening, then that's like assuming it'll just happen on its own. It won't!)


#7

Please just tell me how to do it. Stop being so indirect, just tell me.


#8

@ionatan is not trying to be indirect, but he wants to get you thinking so that you can figure it out and learn something. He wouldn't get anything from constantly responding to people and purposely being unhelpful, but if you actually read his responses, they are thought out and along with reviewing the lessons can help you complete this lesson. I think you might understand it better if you changed your perspective a little bit. He's not going to do it for you, but by asking these kinds of questions, he is trying to guide you down the correct path.

For your question - look at how the example in the lesson does it:

grades.select {|name, grade| grade < 97}

#10

I would learn something if I was told how to do it. Sitting here confused isn't teaching me anything FYI.


#11

I did tell you how to do it. I gave you almost an exact example. You want to assign good_movies to something similar to the example i provided, but with the correct limitations, rating > 3.


#12

If programming was about knowing finished solutions then human programmers would be obsolete.

If I'm able to spot a problem in a shorter amount of time than you, then what should be interesting to you is how I did so, not what the conclusion was.

There's a difference between "fix this for me" and "help me figure this out"

I'm interested in one of them.


#13

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