15. Now You Try


#1

Hi I am having trouble with 15. Now You Try. This is my code. It prints, on three separate lines, as follows

“kettles
mittens
packages”

these are all the symbols from the array and I don’t understand why the program is still not working.

Code Below:


my_array = ["raindrops", :kettles, "whiskers", :mittens, :packages]

symbol_filter = lambda {|x| x.is_a? Symbol}


symbol = my_array.select(&symbol_filter)
puts symbol

What do i need to fix from my code?


#2

You never set any value to packages. It just gives you the name.


#3

Maybe this will help you visualize:

no_values = [ :a, :b, :c ]

puts no_values 
#This will result in
a
b
c

print no_values
[:a, :b, :c] => nil 

with_values = [a:1, b:2, c:3]

puts with_values 
#Now you'll get: 
{:a=>1, :b=>2, :c=>3}

print with_values
[{:a=>1, :b=>2, :c=>3}]


#4

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