前端知识学习

1,
function sum(arr) {
    var s = 0;
    for (var i=arr.length-1; i>=0; i--) {
        s += arr[i];
    }
    return s;
}
2,

function sum(arr) {
    return arr.reduce(function(prev, curr){
        return prev + curr;
    });
}
3,

function sum(arr) {
    var s = 0;
    arr.forEach(function(val) {
        s += val;
    });
  
    return s;
};

4,
function sum(arr) {
    return eval(arr.join("+"));
};