gpt4 book ai didi

ruby-on-rails - 如何展平阵列阵列 - 但不是一直向下

转载 作者:数据小太阳 更新时间:2023-10-29 06:20:13 24 4
gpt4 key购买 nike

什么是最好的转换方式

[[["Club three Team one", 7800], ["Club three Team two", 7801]], [], [["Club four Team one", 7807], ["Club four Team two", 7808]], []]

进入

[["Club three Team one", 7800], ["Club three Team two", 7801], ["Club four Team one", 7807], ["Club four Team two", 7808]]

ruby ? flatten 将其一直转换为

["Club three Team one", 7303, "Club three Team two", 7304, "Club four Team one", 7310, "Club four Team two", 7311]

最佳答案

使用 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]]

关于ruby-on-rails - 如何展平阵列阵列 - 但不是一直向下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5612625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com