arrays - Removing letters from a string and only retaining numbers -
i have array arr
in haml, inside loop.
- item.each |grp, arr = []| - grp.section.each {|abc| arr.push(abc.values_with_units) }
for each iteration, values , units of them change. might ["23 mm", "34 mm", "56 mm"]
, in next iteration might ["25 km/s m", "32 km/s m", "12 km/s m"]
. want rid of units , retain values: in case 1 [23,34,56]
, , in case 2 [25, 32, 12]
.
how can achieve in ruby?
to_i ignores after numbers can following.
array = ['23 mm', '34 mm', '56 mm'] array.map(&:to_i) # [23, 34, 56] array = ['25 km/s m', '32 km/s m', '12 km/s m'] array.map(&:to_i) # [25, 32, 12]
Comments
Post a Comment