Use the Spread Operator to Evaluate Arrays In-Place- someone help me?

Use the Spread Operator to Evaluate Arrays In-Place- someone help me?
0

#1

What is the problem my code ?

Your code so far


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

let numbers = [-12, 160, 0, -3, 51];
let minNum = Math.min(numbers);
console.log(minNum);//NaN 

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 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

Reset the code and only input the spread operator part.

One issue with your code is that arr2 is being assigned a value inside of the func in a way where the result of the assignment wont be recognized outside of the func. This makes arr2 remain undefined outside of the func (scope issue)

Let me know if this helps here


#4

You do not need to declare arr2 inside the function. Just reassign the value. arr2 is meant to be a global variable. When you declare arr2 inside the function, the global variable arr2 (outside the function) retains its’ original value of undefined.