Copy an Array with the Spread Operator 4

Tell us what’s happening:
I don’t understand the use of “num–” in this code.

Your code so far
function copyMachine(arr, num) {
let newArr = ;
while (num >= 1) {
// Only change code below this line
newArr.push([…arr])
// Only change code above this line
num–;
}
return newArr;


function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
  // Only change code below this line
newArr.push([...arr])
  // Only change code above this line
  num--;
}
return newArr;
}

console.log(copyMachine([true, false, true], 2));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

Challenge: Copy an Array with the Spread Operator

Link to the challenge:

the while loop condition is num >= 1, if you don’t decrease num then it is an infinite loop

Thank you for your response.

How does the system know how many iterations to produce? I thought
“num–” simply meant to subtract one iteration

it’s a loop, it does it once for each iteration until num >= 1 is false. when num equals 0 the loop stops

Thank you for clarifying.