我是个新手,所以我对此表示歉意,但是在数组位置中是否有任何实际的方法减去2的倍数呢?

 let numberOne = Math.floor(Math.random() * (15 - 5) + 5),
     numberTwo = 100,
     arrayOne = [],
     arrayTwo = [];
    while (numberTwo > 0){
    numberTwo = numberTwo - numberOne
      arrayOne.push(numberTwo)
    }
    arrayTwo.push(arrayOne[0] - arrayOne[1])
    arrayTwo.push(arrayOne[2] - arrayOne[3])
    console.log(arrayTwo);

最佳答案

您正在从具有随机数增量的数组中减去值。

两个跟随值之差的结果始终是随机值。



let min = 5,
    max = 15,
    numberOne = Math.floor(Math.random() * (max - min) + min),
    numberTwo = 100,
    arrayOne = [],
    arrayTwo = [];

while (numberTwo > 0) {
    numberTwo -= numberOne;
    arrayOne.push(numberTwo);
}

console.log(numberOne);   // random value
console.log(...arrayOne); // all deltas

arrayTwo.push(arrayOne[0] - arrayOne[1]);
arrayTwo.push(arrayOne[2] - arrayOne[3]);

console.log(arrayTwo);

09-25 19:13