loop through two arrays and group them based on a condition

来源:互联网 发布:小米网络助手校正失败 编辑:程序博客网 时间:2024/06/05 20:41

len = [24,71,312,99,89]diff = [11,7,7,21,3]
len.zip(diff).chunk { |l, d| d < 10 }.map { |_, d| d.map(&:first).inject(:+) }# => [24, 383, 99, 89]

0 0
原创粉丝点击