慕的地5204680
//双层for循环
var dataArray = [1,2,3];
var sum = 0;
for (var i=0; i<dataArray.length; i++) {
var result = 1;
for(var j=1; j<=dataArray[i]; j++) {
result *= j;
}
sum += result;
}
console.log(sum);
//利用arguments的callee方法,array的map和reduce方法
var caculateFactorial = function(x) {
if (x===0) {
return 1;
} else {
return x* arguments.callee(x-1);
}
}
var sumArrayFactorial = function(dataList){
return dataList.map(caculateFactorial).reduce((a, b) => a+b);
}
var dataList = [1,2,3,4,5];
sumArrayFactorial(dataList);