Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Blocks Working With Blocks Block Method Practice: Arrays

I HAVE NO IDEA HOW TO GET SOMETHING CHAR GREATER THAN CHAR.LENGTH > 4

I HAVE NO IDEA HOW THESE HAVE TO BE GREATER THAN CHAR LENGTH 4

array_blocks.rb
array = ["Tree", "House"]
house [] = array.select { |item|  item > char.length == 4  }
datavxn
datavxn
6,331 Points

The challenge asks to create a new array named house, pulling in any "item" from the array variables above, whose length is greater than four characters, therefore you must check the length (.length) of all items in the array (iterate), by checking the argument in the block, so "item". Your code is almost there and should look like this:

array = ["Tree", "House"] house = array.select { |item| item.length > 4}

Informationally, you don't need "char" before .length, and using == is asking it to check length equal to 4.

Hope this helps!

3 Answers

Jeremiah Shafer
Jeremiah Shafer
12,388 Points

I think you're overthinking the select method. There's also a typo. Here's how I fixed it:

array = ["Tree", "House"]

array.each { |item| item.chars.length > 4 }
datavxn
datavxn
6,331 Points

You're welcome! Looks like it changed formatting when I posted. "House" starts on a different line.

array = ["Tree", "House"]

house = array.select { |item| item.length > 4}

Thank you for giving me this detailed help on where to start looking at the problem of the challenge.