Ruby Ruby Blocks Working With Blocks Block Method Practice: Arrays

Using the select method, create a new array named house that contains any items from the array variable with a length gr

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_blocks.rb
array = ["Tree", "House"]

2 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,759 Points

Hi Mustafa,

You need to iterate through the array with a block. Test each iteration for .length being greater than 4.

It'll look something like this:

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

I hope that helps !

Steve.

Thanx