'Convert array Ruby
How can I convert ["90 99 8 9 11 22"] to ["90", "99", "8", "9", "11", "22"] in Ruby ?
Solution 1:[1]
With flat_map and split it works with any number of items:
["90 99 8 9 11 22"].flat_map(&:split)
=> ["90", "99", "8", "9", "11", "22"]
> ["90 99 8 9 11 22", "1 2 3"].flat_map(&:split)
=> ["90", "99", "8", "9", "11", "22", "1", "2", "3"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yakov |
