加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 阵列半扁平化

发布时间:2020-12-17 03:00:57 所属栏目:百科 来源:网络整理
导读:想转换这个: [["1","2","3"],["4","5","6"]] 对此: ["1","6"] 要传递到Array.product(),第一个数组可以包含未知数量的其他数组.例如,给出的数组也可以是 [["1","6"],["7","8","9"]] 最后,我需要将论证传递为: otherArray.product(["1","9"]) 提前谢谢!
想转换这个:

[["1","2","3"],["4","5","6"]]

对此:

["1","6"]

要传递到Array.product(),第一个数组可以包含未知数量的其他数组.例如,给出的数组也可以是

[["1","6"],["7","8","9"]]

最后,我需要将论证传递为:

otherArray.product(["1","9"])

提前谢谢!

解决方法

otherArray.product(*[["1","9"]]);

* is used in argument list to unpack array contents to arguments (like
here) or to pack arguments into an array,like in “def mymethod(*args)”

参考:http://www.justskins.com/forums/apply-method-to-array-17387.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读