" We have defined a function, copyMachine
which takes arr
(an array) and num
(a number) as arguments. The function is supposed to return a new array made up of num
copies of arr
. We have done most of the work for you, but it doesn’t work quite right yet. Modify the function using spread syntax so that it works correctly (hint: another method we have already covered might come in handy here!)."
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));
I actually have two questions that I’m trying to understand:
while (num >= 1) ------- why do we need this?
num–; why do we need this?
I hope I’ve made myself clear.
Regards!