Tell us what’s happening:
When you go to this section and read the left side where it teaches the … operator and shows you examples of it in action where in their does it tell you to use push?..yeah it doesn’t
They showed this
let thisArray = [true, true, undefined, false, null];
let thatArray = [...thisArray];
// thatArray equals [true, true, undefined, false, null]
// thisArray remains unchanged, and is identical to thatArray
And as you can tell below i tried to do the above, like as instructed…I feel there are many more cases of bad instructions throughout this javascript course.
My Code
function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
// Only change code below this line
newArr = [...arr];
// Only change code above this line
num--;
}
return newArr;
}
console.log(copyMachine([true, false, true], 2));
** The Solution **
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));