I'm a beginner to programming and I was given this problem to solve with ruby:
Given an array containing some strings, return an array containing the length of those strings. You are supposed to write a method named 'length_finder' to accomplish this task.
I wrote:
def length_finder(input_array)
a = [ ]
input_array.each { |n| puts n.length.to_i }
a << n
a
end
I got an error undefined local variable or method `n'. What's wrong with the code?
map, the Ruby solution to this is a one-liner.