Javascript 正在尝试添加。上一笔款项的8
我不知道该如何表达这个问题,因为我对算法还比较陌生。我试图构建一个以9为起点的函数,然后我想加上9+8得到17的和,然后再加上17+8得到25,以此类推,然后重复一定的次数,将每个和存储到一个数组中。据我所知,你的函数应该是这样的Javascript 正在尝试添加。上一笔款项的8,javascript,Javascript,我不知道该如何表达这个问题,因为我对算法还比较陌生。我试图构建一个以9为起点的函数,然后我想加上9+8得到17的和,然后再加上17+8得到25,以此类推,然后重复一定的次数,将每个和存储到一个数组中。据我所知,你的函数应该是这样的 /* startingValue is a number, the value you want from where you want to start increment is a number, the number we add to each itera
/*
startingValue is a number, the value you want from where you want to start
increment is a number, the number we add to each iteration
repeats is a number, how many times we will repeat the incrementation
*/
function incrementMultipleTimes(startingValue, increment, repeats) {
// Our starting array
let values = [];
// For each of the repeat wanted, we will run the code once more
for (var i = 0; i <= repeats; i++) {
// Set a value in the array equal to our starting value + the increment multiplied the number of times we incremented.
values[i] = startingValue + (increment * i);
}
// return the value
return values;
}
/*
startingValue是一个数字,是您希望从何处开始的值
增量是一个数字,是我们添加到每个迭代中的数字
repeats是一个数字,我们将重复递增多少次
*/
函数递增倍数(起始值、递增、重复){
//我们的首发阵容
让值=[];
//对于每个需要的重复,我们将再次运行代码
对于(var i=0;i)因此,您希望从n开始计算一个运行总数,并将n-1添加到其中,直到n为零。问题是什么?请编辑您的问题,以显示您所做的工作、遇到的问题、错误、预期输出与实际输出等。否则,不清楚您的具体问题在哪里。如果您正在寻找一个此外,您可以在此处查看: