Can't solve: Copy an Array with the Spread Operator

Tell us what’s happening:

So the task is to store the above code in a spread operator. I tried to do that but, it doesn’t seem to work. Where am i going wrong

Your code so far


function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
  // Only change code below this line
let obj = [...arr];
newArr = obj;
//newArray = [..arr]; doesns't work either
  // 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/83.0.4103.61 Safari/537.36.

Challenge: Copy an Array with the Spread Operator

Link to the challenge:

Hey,

the key is in this sentence:

The function is supposed to return a new array made up of num copies of arr .

The “num copies” are missing. So far you code creates one copy, but there should be as many copies as the number stored in num.

2 Likes