I need to do the following:
Write a function that takes a String and returns an Array/list with the length of each word added to each element
Examples:
add_length('apple ban') => ["apple 5", "ban 3"]
add_length('you will win') => ["you 3", "will 4", "win 3"]
I can find the length of each word but my question is, how do I then create a new array appending the lengths to each respective element? I think i need to use map again, but I am not sure how...
This is how I have worked out the lengths:
def add_length(str)
str.split(" ").map(&:length).to_s
end