Instructions
Use it with filtering methods like select.
Create a function select_long_words that returns words
with more than 5 characters.
Use it.length > 5 in your select block.
Hints:
- Use .select { it.length > 5 }
- 'it' works with any block method
- select keeps elements where block is true
Your Code
def select_long_words(words)
words.select { it.length > 5 }
end
RSpec.describe "select_long_words with 'it'" do
it "selects words longer than 5 chars" do
result = select_long_words(["hi", "hello", "programming", "ruby"])
expect(result).to eq(["programming"])
end
it "handles empty array" do
expect(select_long_words([])).to eq([])
end
it "handles all short words" do
expect(select_long_words(["a", "bb", "ccc"])).to eq([])
end
end
Results
Click "Run Tests" to see results