diff --git a/challenges/02-javascript-algorithms-and-data-structures/es6.json b/challenges/02-javascript-algorithms-and-data-structures/es6.json
index a222694c3d..fe9758ec75 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/es6.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/es6.json
@@ -285,20 +285,15 @@
},
{
"id": "587d7b88367417b2b2512b46",
- "title": "Default Parameters",
+ "title": "Write Functions with Default Parameters",
"description": [
- "In order to help us create more flexible functions, ES2015 introduces default parameters for functions.",
+ "In order to help us create more flexible functions, ES6 introduces default parameters for functions.",
"Check out this code:",
- "function greeting(name = \"Anonymous\") {
",
- " return \"Hello \" + name;
",
- "}
",
- "console.log(greeting(\"John\")); // Hello John
",
- "console.log(greeting()); // Hello Anonymous
",
- "The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, when you do not provide a value for your parameter, the parameter will receive its default value. You can add default values for as many parameters as you want.",
- "Instructions.",
- "Modify the following code by adding a default parameter for the increment function so that it will always return a valid number and it will add 1 to the number parameter in case value is not specified.",
- "Note",
- "Don't forget to use strict mode."
+ "
function greeting(name = \"Anonymous\") {", + "The default parameter kicks in when the argument is not specified (it is undefined). As you can see in the example above, the parameter
return \"Hello \" + name;
}
console.log(greeting(\"John\")); // Hello John
console.log(greeting()); // Hello Anonymous
name
will receive its default value \"Anonymous\"
when you do not provide a value for the parameter. You can add default values for as many parameters as you want.",
+ "increment
by adding default parameters so it will always return a valid number and it will add 1 to number
if value
is not specified.",
+ "Notefunction howMany(...args) {
",
- " return \"You have passed \" + args.length + \" arguments.\";
",
- "}
",
- "console.log(howMany(0, 1, 2)); // You have passed 3 arguments.
",
- "console.log(howMany(\"string\", null, [1, 2, 3], { })); // You have passed 4 arguments.
",
- "The rest operator eliminates the need to check the arguments object and allows us to apply map, filter and reduce on the parameters array.",
- "Instructions.",
- "Modify the sum function so that is uses the rest operator and it works in the same way with any number of parameters.",
- "Note",
- "Don't forget to use strict mode."
+ "function howMany(...args) {", + "The rest operator eliminates the need to check the
return \"You have passed \" + args.length + \" arguments.\";
}
console.log(howMany(0, 1, 2)); // You have passed 3 arguments
console.log(howMany(\"string\", null, [1, 2, 3], { })); // You have passed 4 arguments.
args
array and allows us to apply map()
, filter()
and reduce()
on the parameters array.",
+ "sum
so that is uses the rest operator and it works in the same way with any number of parameters.",
+ "Notevar arr = [6, 89, 3, 45];
",
- "var maximus = Math.max.apply(null, arr); // returns 89
",
- "We had to use Math.max.apply(null, arr), because Math.max(arr) returns NaN. Math.max expects a comma separated arguments, just not an array.
",
- "However, the spread operator makes this syntax much better to read and maintain.",
- "const arr = [6, 89, 3, 45];
",
- "const maximus = Math.max(...arr); // returns 89
",
- "...arr returns an un-packed array content. It spreads the array.",
- "However, this is in-place; like the argument to a function. You cannot do this:",
- "const spreaded = ...arr; // will throw a syntax error
",
- "Instructions.",
- "Copy all contents of arr1 into another array arr2."
+ "ES6 introduces the spread operator, which allows us to expand arrays and other expressions in places where multiple parameters or elements are expected.",
+ "The ES5 code below uses apply()
to compute the maximum value in an array:",
+ "var arr = [6, 89, 3, 45];", + "We had to use
var maximus = Math.max.apply(null, arr); // returns 89
Math.max.apply(null, arr)
because Math.max(arr)
returns NaN
. Math.max()
expects comma-separated arguments, but not an array.",
+ "The spread operator makes this syntax much better to read and maintain.",
+ "const arr = [6, 89, 3, 45];", + "
const maximus = Math.max(...arr); // returns 89
...arr
returns an unpacked array. In other words, it spreads the array.",
+ "However, the spread operator only works in-place, like in an argument to a function or in an array literal. The following code will not work:",
+ "const spreaded = ...arr; // will throw a syntax error", + "
arr1
into another array arr2
using the spread operator."
],
"challengeSeed": [
"const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];",
- "/* Alter code below this line */",
- "const arr2 = undefined; // change this",
- "/* Alter code above this line */",
+ "const arr2 = [];",
+ "// change code below this line",
+
+ "// change code above this line",
"arr1.push('JUN');",
- "console.log(arr2); // should not be affected"
+ "console.log(arr2); // arr2 should not be affected"
],
"tests": [
"// Test arr2 is correct copy of arr1",
@@ -387,29 +376,26 @@
},
{
"id": "587d7b89367417b2b2512b49",
- "title": "No Title Two",
+ "title": "Use Destructuring Assignment with Objects",
"description": [
- "We earlier saw how spread operator can effectively spread or unpack the contents of the array.",
- "We can do something similar with objects as well. Objects in JavaScript are a key-value pair collections.",
- "Consider the following:",
- "const voxel = {x: 3.6, y: 7.4, z: 6.54 };
",
- "const x = voxel.x; // x = 3.6
",
- "const y = voxel.y; // y = 7.4
",
- "const z = voxel.z; // z = 6.54
",
- "Here's the same assignment statement with ES6 destructuring syntax",
- "const { x, y, z } = voxel; // x = 3.6, y = 7.4, z = 6.54
",
- "If instead, you want to store the values of voxel.x into a, voxel.y into b and so on; you have that freedom as well.",
- "const { x : a, y : b, z : c } = voxel // a = 3.6, y = 7.4, z = 6.54
",
- "You may read it as \"get the field x and copy the value in a\" and so on.",
- "Instructions.",
- "Use destructuring to obtain the length of the string greeting"
+ "We earlier saw how spread operator can effectively spread, or unpack, the contents of the array.",
+ "We can do something similar with objects as well. Destructuring assignment is special syntax for neatly assigning values taken directly from an object to variables.",
+ "Consider the following ES5 code:",
+ "const voxel = {x: 3.6, y: 7.4, z: 6.54 };", + "Here's the same assignment statement with ES6 destructuring syntax:", + "
const x = voxel.x; // x = 3.6
const y = voxel.y; // y = 7.4
const z = voxel.z; // z = 6.54
const { x, y, z } = voxel; // x = 3.6, y = 7.4, z = 6.54", + "If instead you want to store the values of
voxel.x
into a
, voxel.y
into b
, and voxel.z
into c
, you have that freedom as well.",
+ "const { x : a, y : b, z : c } = voxel // a = 3.6, y = 7.4, z = 6.54", + "You may read it as \"get the field
x
and copy the value into a
,\" and so on.",
+ "greeting
"
],
"challengeSeed": [
"const greeting = 'itadakimasu'",
- "/* Alter code below this line */",
- "const len = 0; // change this",
- "/* Alter code above this line */",
- "console.log(len); // should be using destructuring"
+ "// change code below this line",
+ "const length = 0; // change this",
+ "// change code above this line",
+ "console.log(length); // should be using destructuring"
],
"tests": [
"// Test len is 11",