Use the Spread Operator to Evaluate Arrays In-Place, adding the proper solution. (Fixes #35022) (#35037)

* Adding proper solution for spread operation

Use the Spread Operator to Evaluate Arrays In-Place: adding the proper solution for the challenge

* made some more changes

* Fixed the Solution in es6 class constructor guide

Fixed the vegetable solution in Guide: Use class Syntax to Define a Constructor Function
This commit is contained in:
Sidak Singh Aulakh
2019-02-05 14:09:52 +05:30
committed by Ahmad Abdolsaheb
parent 2baac0f8fe
commit fe085246c8
2 changed files with 15 additions and 18 deletions

View File

@ -19,22 +19,6 @@ Put a constructor with a parameter called `name`, and set it to `this.name`.
## Solution:
```javascript
function makeClass() {
"use strict";
/* Alter code below this line */
class Vegetable {
constructor(name){
this.name = name;
}
}
/* Alter code above this line */
return Vegetable;
}
```
=======
Spoiler Warning: here is a basic solution to this challenge in case you're stuck.
```javascript
@ -43,8 +27,8 @@ function makeClass() {
/* Alter code below this line */
class Vegetable {
constructor(Vegetable){
this.Vegetable = Vegetable;
constructor(name){
this.name = name;
}
}

View File

@ -35,5 +35,18 @@ let numbers = [-12, 160, 0, -3, 51];
let minNum = Math.min(...numbers);
console.log(minNum);//-12
```
# SPOILER WARNING: SOLUTION AHEAD
### The Solution
> Unpacking the arr1 using the spread operator and then copying those values to arr2
```javascript
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
(function() {
"use strict";
arr2 = [...arr1]; // change this line
})();
console.log(arr2);
```
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->