1
all right? I’m learning Ruby So I have a Ruby Fundamentals exercise that asks for the following: I have to add the items of a string, the problem is that this string is like this:
7
-3
10
0
-5
I tried to use reduce and even inject so that they add up, the problem is that I have no idea how to get them lined up, tried with chomp and was not, not yet tried with gsub.
class Numbers
def sum_text(numbers_text)
numbers_text.map(&:to_f).reduce(:+)
end
end
From Ruby 2.4.6 you can replace this
.reduce(&:+)
for.sum
– matheusma37