编写函数harmonic progression),计算1+1/2+1/3+...1/n,当其和值大于10时n的值;
思路
function a(i,n)
{
n++;
i+=1/(1+i)
if(大于10)
return n
else
a(i,n)}
const harmonic_progression = function() {
let n = 1;
let sum = 0;
while (sum <= 10) {
sum += 1 / n;
n++;
}
return n;
}
console.log(harmonic_progression()); // 12368