Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Salman Akram
Courses Plus Student 40,065 PointsRuby Blocks Question Confusion
Just some confusion on question
Question: Using the select method, create a new array named house that contains any items from the array variable with a length greater than four characters.
array = ["Tree", "House"]
array.select {|house| house.length > 4}
2 Answers
Maciej Czuchnowski
36,441 PointsYou were close, but you did not create a new array named house. The code should be something like this:
house = array.select { |h| h.length > 4 }
Peter Zurkuhlen
6,277 PointsSalman Akram , should be written as follows:
array = ["Tree", "House"]
house = array.select { |item| item.length > 4 }
Note: "item" is an arbitrary choice. Doesn't matter what you use for your local variable in the block. Just use something that works for your own personal reference/preference. For example, you could get the same result if you wrote the code as follows:
array = ["Tree", "House"]
house = array.select { |blurp| blurp.length > 4 }
etc..
The "blurp" is just a local variable referencing each item in the array, independently, and testing it for being "> 4".
Good luck, and happy learning! :)
Salman Akram
Courses Plus Student 40,065 PointsSalman Akram
Courses Plus Student 40,065 PointsThank you, I was trying to figure out which one array, one is new array called house or replace another exist array, keep getting errors message. :(