Copy machine code not working

Copy machine code not working
0

#1

newArr.push([…arr]); didn’t work i’m confused


Copy an Array with the Spread Operator...arr
#2

What is your full code?


#4

herer is my code:

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

// change code here to test different cases:
console.log(copyMachine([true, false, true], 2));

#5

That is because you declared newArr but never assigned it a value. Inside your while loop you start trying to call the push method on newArr, but newArr was never declared as an array.


#6

thanks it works perfectly