gpt4 book ai didi

ruby-on-rails - ruby /rails : Merge result of map

转载 作者:数据小太阳 更新时间:2023-10-29 08:17:22 31 4
gpt4 key购买 nike

我有 @products 集合,我想将 image_ids 合并到单个数组。这是 @products.map(&:image_ids) 的输出:

@products.map(&:image_ids)
=> [[1654, 1655, 1656],
[1649, 1650, 1652, 1653],
[1625],
[1624],
[1623],
[1622],
[1621],
[1620],
[1619],
[1618]]

最佳答案

使用 flat_map 执行以下操作:

@products.flat_map(&:image_ids)

关于ruby-on-rails - ruby /rails : Merge result of map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22012190/

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