From fe085246c80d5bfc9d65db8b245ae7a9106e4a2c Mon Sep 17 00:00:00 2001 From: Sidak Singh Aulakh Date: Tue, 5 Feb 2019 14:09:52 +0530 Subject: [PATCH] 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 --- .../index.md | 20 ++----------------- .../index.md | 13 ++++++++++++ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function/index.md index 9e2a465f30..84b23a12e5 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-class-syntax-to-define-a-constructor-function/index.md @@ -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; } } diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place/index.md index 2e188456f5..f65b77276f 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/es6/use-the-spread-operator-to-evaluate-arrays-in-place/index.md @@ -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); +```