Use the Spread Operator to Evaluate Arrays In-Place bug

Use the Spread Operator to Evaluate Arrays In-Place bug
0

#1

Tell us what’s happening:

There seems to be a bug here. This code absolutely uses the spread operator to duplicate the array, but it’s not passing the “Array was duplicated using …arr1”
Your code so far


const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
(function() {
  "use strict";
  arr2 = new Array(...arr1); // change this line
})();
console.log(arr2);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place


#2

This does not create a copy of arr1.

Try using a literal array with the spread operator. That is the easiest and most readable way.