Not quite sure I understand the instruction correctly

Could I please ask for some clarification, here? Just want to make sure that I understand. What I gather from the instructions is that we are looking to return an array made up of “num” and strictly numbers. What I think is being said here is, make sure that the property is a number or an integer type… Am I grasping the instructions, if not could someone please help maybe reword the instructions or just throw a hint…
Thanks in advance.

  **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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36

Challenge: Copy an Array with the Spread Operator

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/copy-an-array-with-the-spread-operator

Not quite. As the instructions say:

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

So you are returning an array of arrays, or a two-dimensional array. This is show below the instructions, for example:

copyMachine([true, false, true], 2) should return [[true, false, true], [true, false, true]]

Do you see how the function returns an array with two sub arrays in it? The second argument tells you how many copies of the array to return. It doesn’t matter what types of values are in the array, you are just making copies of the array.

2 Likes

yes, indeed. I glanced at it just now, and I noticed that it is a two-dim array and as such I reckon I will need to loop through it in order to get to the nested elements, won’t I?

That is one way to do it but the instructions specifically say to use the spread syntax to make the copy, so you shouldn’t use any loops here.

Thank you very much.

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