Instructions Not Clear...Please Fix

Tell us what’s happening:

When you go to this section and read the left side where it teaches the … operator and shows you examples of it in action where in their does it tell you to use push?..yeah it doesn’t

They showed this


let thisArray = [true, true, undefined, false, null];
let thatArray = [...thisArray];

// thatArray equals [true, true, undefined, false, null]
// thisArray remains unchanged, and is identical to thatArray

And as you can tell below i tried to do the above, like as instructed…I feel there are many more cases of bad instructions throughout this javascript course.

My Code


function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
  // Only change code below this line
    newArr = [...arr];
  // Only change code above this line
  num--;
}
return newArr;
}

console.log(copyMachine([true, false, true], 2));

** The Solution **

function copyMachine(arr, num) {
  let newArr = [];
  while (num >= 1) {
    // change code below this line
    newArr.push([...arr]);
    // change code above this line
    num--;
  }
  return newArr;
}

// change code here to test different cases:
console.log(copyMachine([true, false, true], 2));
1 Like

Right, but in the solution, if you notice, you are still using the spread operator to copy the array.

You could also solve this easily without push, just by using a for loop to count up and use as an index:

function copyMachine(arr, num) {
  let newArr = [];
  for (let i = 0; i < num; i += 1) {
    newArr[i] = [...arr];
  }
  return newArr;
}

I don’t know. Would that be clearer? Maybe it’s confusing because push is also used to manipulate arrays.

Hey Jordan,

thanks for your message.

Because a lot of the FCC curriculum is created by professional developers it’s great to get feedback of actual users.

Which part of the description led to your confusion?
How would you improve the description?