ruby - Array elements to integers -
i have array of strings containing numbers:
array = ["1", "2", "3"]
i want convert every string in array integer.
array.each { |n| n.to_i }
not work, because
p array.inject(:+)
returns "123"
(string) rather 6
(integer)
array = ["1", "2", "3"] new_array = array.map { |n| n.to_i } p new_array.inject(:+) => 6
Comments
Post a Comment