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

Popular posts from this blog

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Handling constructor related functions while testing with mocha and sinon -