for循环太过简单,不赘述
var arr = [2, 5, 6, 8, 6, 8, 7, 12, 1, 3, 4, 100]; function totalFn(arr) { let total = 0; let len = arr.length - 1; function fn(len) { total += arr[len]; if (len === 0) return total; fn(len - 1); } fn(len); return total; } let res = totalFn(arr); console.log(res);