In the “Basic Data Structures: Copy an Array with the Spread Operator” we have to push the array with the spread operator.
One of the requirements for this exercise is: copyMachine([true, false, true], 2)
should return [[true, false, true], [true, false, true]]
When I use newArr.push(arr)
, the fcc console returns [ [ true, false, true ], [ true, false, true ] ]
, when I use the spread operator newArr.push(...arr)
, the fcc console returns [ true, false, true, true, false, true ]
but the exercise is counted as correct.
So although there’s a difference between the two I don’t exactly get what it is and why would we need to use the spread operator instead of just calling the whole array.