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:
		
				
					committed by
					
						 Ahmad Abdolsaheb
						Ahmad Abdolsaheb
					
				
			
			
				
	
			
			
			
						parent
						
							2baac0f8fe
						
					
				
				
					commit
					fe085246c8
				
			| @@ -19,22 +19,6 @@ Put a constructor with a parameter called `name`, and set it to `this.name`. | |||||||
|  |  | ||||||
| ## Solution: | ## 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. | Spoiler Warning: here is a basic solution to this challenge in case you're stuck. | ||||||
|  |  | ||||||
| ```javascript | ```javascript | ||||||
| @@ -43,8 +27,8 @@ function makeClass() { | |||||||
|   /* Alter code below this line */ |   /* Alter code below this line */ | ||||||
|  |  | ||||||
|    class Vegetable { |    class Vegetable { | ||||||
|      constructor(Vegetable){ |      constructor(name){ | ||||||
|        this.Vegetable = Vegetable; |        this.name = name; | ||||||
|    |    | ||||||
|      } |      } | ||||||
|    } |    } | ||||||
|   | |||||||
| @@ -35,5 +35,18 @@ let numbers = [-12, 160, 0, -3, 51]; | |||||||
| let minNum = Math.min(...numbers); | let minNum = Math.min(...numbers); | ||||||
| console.log(minNum);//-12 | 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  --> | <!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds  --> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user