Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

获取数据中一条数据的和?

image
image
image
请问我想要子数组的每一个 rightPercent 的和。该怎么办?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
function sum(arr) {
    return arr.reduce(function(s1, c1){
        return s1 + c1.reduce(function(s2, c2){
            return s2 + c2.rightPercent;
        }, 0);
    }, 0);
}

sum([[{rightPercent: 10}], [{rightPercent: 10}, {rightPercent: 10}]]); // 30

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...