Tell us what’s happening:
Hello Sirs
Good day,
What will be the issues using unshift instead push?
Please…
Your code so far
function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
// Only change code below this line
newArr.unshift([...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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Challenge: Basic Data Structures - Copy an Array with the Spread Operator
For this challenge both push and unshift will pass, and there’s really no issue with using on or the other for this challenge at least. You would just have to keep in mind that unshift will add to the beginning of the array and push will add the end of the array. Because the challenge is looking for [ [ true, false, true ], [ true, false, true ] ] no matter if you use push or unshift the order is still going to be the same since the two arrays are the same. Now, if the arrays had different values in them then you would have to think about using unshift or push to match the order they wanted