Add*_*ddy 62 ruby ruby-on-rails
转换它的最佳方法是什么?
[[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []]
Run Code Online (Sandbox Code Playgroud)
成
[["Club three Team one", 7800], ["Club three Team two", 7801], ["Club four Team one", 7807], ["Club four Team two", 7808]]
Run Code Online (Sandbox Code Playgroud)
在红宝石?flatten将这一直转换为
["Club three Team one", 7303, "Club three Team two", 7304, "Club four Team one", 7310, "Club four Team two", 7311]
Run Code Online (Sandbox Code Playgroud)
fl0*_*00r 109
使用flatten(1) http://apidock.com/ruby/Array/flatten
your_array = [[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []]
your_array.flatten(1)
#=> [["Club three Team one", 7800], ["Club three Team two", 7801], ["Club four Team one", 7807], ["Club four Team two", 7808]]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27814 次 |
| 最近记录: |