Basic Data Structures - Copy an Array with the Spread Operator

Tell us what’s happening:
Hello Sirs
Good day,
What will be the issues using unshift instead push?


Your code so far

function copyMachine(arr, num) {
  let newArr = [];
  while (num >= 1) {
    // Only change code below this line
    // Only change code above this line
  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/ Safari/537.36

Challenge: Basic Data Structures - Copy an Array with the Spread Operator

Link to the challenge:

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

1 Like

Thanks a lot Sir Cods :smiley:
God Bless

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.