Tell us what’s happening:
What should I do?
Your code so far
function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
// Only change code below this line
newArr.num = [...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 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0.
Challenge: Copy an Array with the Spread Operator
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Hi @amejl172 !
I edited you post title to remove the link and replace it with a more descriptive title.
You will get more responses to your posts if you avoid placing links in the title.
2 Likes
Thanks for helping me with that.
So the issue is here.
amejl172:
newArr.num
The whole reason why we are using the spread operator to copy the array in the first place is to add that to the newArr. Right?
So there is helpful array method you can use that adds elements to an array.
2 Likes
Is newArr.num the only thing I need to change in the code?
Yes.
You got the spread operator right but the first part is wrong.
1 Like
Should I use some kind of .slice() or .splice() method in this challenge?
ILM
January 20, 2021, 7:45am
8
they don’t seem necessary. how do you add new elements to an array?
1 Like
It worked, thanks for the help both of you.
1 Like
system
Closed
July 21, 2021, 7:48pm
12
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.