Tell us what’s happening:
Describe your issue in detail here.
I do not understand what this codes is all about.
num is an argument for 2, while arr is an argument for [true, false, true].
but i can not see any spread operator or slice method 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
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/115.0.0.0 Safari/537.36 Edg/115.0.1901.188
Challenge: Basic Data Structures - Copy an Array with the Spread Operator
Tell us what’s happening:
Describe your issue in detail here.
Or let me humbly say I do not totally understand the function of the while loop here.
while 2 >= 1
something happens …
kind of confused here
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
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/115.0.0.0 Safari/537.36 Edg/115.0.1901.188
Challenge: Basic Data Structures - Copy an Array with the Spread Operator
Thank you jwilkins. But pls can you help with another example because I am still quite confused. It is not really about the answer but how the function works to get to the answer. In case of next time I am confronted with a similar code
and I wanted to copy that list of numbers to a new variable called newListOfNumbers
let newListOfNumbers = [...listOfNumbers]
now newListOfNumbers would result in the array [1,2,3,4,5]
In this challenge, you need to copy the arr using the spread operator.
You also need to use the array method for adding new elements to the end of the array.
When you do those two things, then the test will pass