diff --git a/challenges/02-javascript-algorithms-and-data-structures/es6.json b/challenges/02-javascript-algorithms-and-data-structures/es6.json index 8e72dfe0f3..f0084c6c1d 100644 --- a/challenges/02-javascript-algorithms-and-data-structures/es6.json +++ b/challenges/02-javascript-algorithms-and-data-structures/es6.json @@ -40,7 +40,7 @@ "
", "Replace var with let" ], - "challengeSeed": [ + "challengeSeed": [ "var catName;", "var quote;", "function catTalk() {", @@ -81,10 +81,10 @@ "Fix the code so that i declared in the if statement is a separate variable than i declared in the first line of the function. Be certain not to use the var keyword anywhere in your code.", "This exercise is designed to illustrate the difference between how var and let keywords assign scope to the declared variable. When programming a function similar to the one used in this exercise, it is often better to use different variable names to avoid confusion." ], - "challengeSeed": [ + "challengeSeed": [ "", "function checkScope() {", - "\"use strict\";", + "\"use strict\";", " var i = \"function scope\";", " if (true) {", " i = \"block scope\";", @@ -115,9 +115,9 @@ "
", "Change the code so that all variables are declared using let or const. Use let when you want the variable to change, and const when you want the variable to remain constant. Also, rename variables declared with const to conform to common practices, meaning constants should be in all caps" ], - "challengeSeed": [ + "challengeSeed": [ "function printManyTimes(str) {", - " \"use strict\";", + " \"use strict\";", "", " // change code below this line", "", @@ -153,10 +153,10 @@ "
", "An array is declared as const s = [5, 7, 2]. Change the array to [2, 5, 7] using various element assignment." ], - "challengeSeed": [ + "challengeSeed": [ "const s = [5, 7, 2];", "function editInPlace() {", - " \"use strict\";", + " \"use strict\";", " // change code below this line", "", " // s = [2, 5, 7]; <- this is invalid", @@ -186,7 +186,7 @@ "
", "In this challenge you are going to use Object.freeze to prevent mathematical constants from changing. You need to freeze MATH_CONSTANTS object so that noone is able alter the value of PI or add any more properties to it." ], - "challengeSeed": [ + "challengeSeed": [ "function freezeObj() {", " \"use strict\";", " const MATH_CONSTANTS = {", @@ -196,7 +196,7 @@ "", "", " // change code above this line", - " try {", + " try {", " MATH_CONSTANTS.PI = 99;", " } catch( ex ) {", " console.log(ex);", @@ -231,7 +231,7 @@ "
", "Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax. Also make sure nothing is defined using the keyword var." ], - "challengeSeed": [ + "challengeSeed": [ "var magic = function() {", " \"use strict\";", " return new Date();", @@ -259,7 +259,7 @@ "
", "Rewrite the myConcat function which appends contents of arr2 to arr1 so that the function uses arrow function syntax." ], - "challengeSeed": [ + "challengeSeed": [ "var myConcat = function(arr1, arr2) {", " \"use strict\";", " return arr1.concat(arr2);", @@ -272,7 +272,7 @@ "getUserInput => assert(getUserInput('index').match(/const\\s+myConcat/g), 'message: myConcat should be a constant variable (by using const).');", "assert(typeof myConcat === 'function', 'message: myConcat should be a function');", "assert(() => { const a = myConcat([1], [2]); return a[0] == 1 && a[1] == 2; }, 'message: myConcat() returns the correct array');", - "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');" + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');" ], "type": "waypoint", "releasedOn": "Feb 17, 2017", @@ -293,7 +293,7 @@ "
", "Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array realNumberArray and store the new array in the variable squaredIntegers." ], - "challengeSeed": [ + "challengeSeed": [ "const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];", "const squareList = (arr) => {", " \"use strict\";", @@ -311,7 +311,7 @@ "getUserInput => assert(getUserInput('index').match(/const\\s+squaredIntegers/g), 'message: squaredIntegers should be a constant variable (by using const).');", "assert(Array.isArray(squaredIntegers), 'message: squaredIntegers should be an array');", "assert(squaredIntegers[0] === 16 && squaredIntegers[1] === 1764 && squaredIntegers[2] === 36, 'message: squaredIntegers should be [16, 1764, 36]');", - "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');", + "getUserInput => assert(!getUserInput('index').match(/function/g), 'message: function keyword was not used.');", "getUserInput => assert(!getUserInput('index').match(/(for)|(while)/g), 'message: loop should not be used');", "getUserInput => assert(getUserInput('index').match(/map|filter|reduce/g), 'message: map, filter, or reduce should be used');" ], @@ -331,7 +331,7 @@ "
", "Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified." ], - "challengeSeed": [ + "challengeSeed": [ "const increment = (function() {", " \"use strict\";", " return function increment(number, value) {", @@ -362,9 +362,9 @@ "
", "Modify the function sum so that is uses the rest operator and it works in the same way with any number of parameters." ], - "challengeSeed": [ + "challengeSeed": [ "const sum = (function() {", - " \"use strict\";", + " \"use strict\";", " return function sum(x, y, z) {", " const array = [ x, y, z ];", " return array.reduce((a, b) => a + b, 0);", @@ -400,9 +400,9 @@ "
", "Copy all contents of arr1 into another array arr2 using the spread operator." ], - "challengeSeed": [ - "const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];", - "let arr2;", + "challengeSeed": [ + "const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];", + "let arr2;", "(function() {", " \"use strict\";", " arr2 = []; // change this line", @@ -435,7 +435,7 @@ "
", "Use destructuring to obtain the length of the input string str, and assign the length to len in line." ], - "challengeSeed": [ + "challengeSeed": [ "function getLength(str) {", " \"use strict\";", "", @@ -470,7 +470,7 @@ "
", "Use destructuring assignment to obtain max of forecast.tomorrow and assign it to maxOfTomorrow." ], - "challengeSeed": [ + "challengeSeed": [ "const LOCAL_FORECAST = {", " today: { min: 72, max: 83 },", " tomorrow: { min: 73.3, max: 84.6 }", @@ -509,10 +509,10 @@ "
", "Use destructuring assignment to swap the values of a and b so that a receives the value stored in b, and b receives the value stored in a." ], - "challengeSeed": [ + "challengeSeed": [ "let a = 8, b = 6;", "(() => {", - " \"use strict\";", + " \"use strict\";", " // change code below this line", " ", " // change code above this line", @@ -542,7 +542,7 @@ "
", "Use destructuring assignment with the rest operator to perform an effective Array.prototype.slice() so that arr is a sub-array of the original array source with the first two elements ommitted." ], - "challengeSeed": [ + "challengeSeed": [ "const source = [1,2,3,4,5,6,7,8,9,10];", "function removeFirstTwo(list) {", " \"use strict\";", @@ -579,7 +579,7 @@ "
", "Use destructuring assignment within the argument to the function half to send only max and min inside the function." ], - "challengeSeed": [ + "challengeSeed": [ "const stats = {", " max: 56.78,", " standard_deviation: 4.34,", @@ -589,9 +589,9 @@ " average: 35.85", "};", "const half = (function() {", - " \"use strict\"; // do not change this line", + " \"use strict\"; // do not change this line", "", - " // change code below this line", + " // change code below this line", " return function half(stats) {", " // use function argument destructuring", " return (stats.max + stats.min) / 2.0;", @@ -626,7 +626,7 @@ "
", "Use template literal syntax with backticks to display each entry of the result object's failure array. Each entry should be wrapped inside an li element with the class attribute text-warning, and listed within the resultDisplayArray." ], - "challengeSeed": [ + "challengeSeed": [ "const result = {", " success: [\"max-length\", \"no-amd\", \"prefer-arrow-functions\"],", " failure: [\"no-var\", \"var-on-top\", \"linebreak\"],", @@ -673,7 +673,7 @@ "
", "Use simple fields with object literals to create and return a Person object." ], - "challengeSeed": [ + "challengeSeed": [ "const createPerson = (name, age, gender) => {", " \"use strict\";", " // change code below this line", @@ -706,8 +706,8 @@ "
", "Refactor the function setGear inside the object bicycle to use the shorthand syntax described above." ], - "challengeSeed": [ - + "challengeSeed": [ + "// change code below this line", "const bicycle = {", " gear: 2,", @@ -744,7 +744,7 @@ "Use class keyword and write a proper constructor to create the Vegetable class.", "The Vegetable lets you create a vegetable object, with a property name, to be passed to constructor." ], - "challengeSeed": [ + "challengeSeed": [ "function makeClass() {", " \"use strict\";", " /* Alter code below this line */", @@ -786,7 +786,7 @@ "This is the power of getter or setter - you are creating an API for another user, who would get the correct result, no matter which one you track.", "In other words, you are abstracting implementation details from the consumer." ], - "challengeSeed": [ + "challengeSeed": [ "function makeClass() {", " \"use strict\";", " /* Alter code below this line */", @@ -827,7 +827,14 @@ "
", "Add the appropriate import statement that will allow the current file to use the capitalizeString function. The file where this function lives is called \"string_functions\", and it is in the same directory as the current file." ], - "challengeSeed": [ + "head": [ + "window.require = function (str) {", + "if (str === 'string_functions') {", + "return {", + "capitalizeString: str => str.toUpperCase()", + "}}};" + ], + "challengeSeed": [ "\"use strict\";", "capitalizeString(\"hello!\");" ], @@ -852,7 +859,10 @@ "
", "Below are two variables that I want to make available for other files to use. Utilizing the first way I demonstrated export, export the two variables." ], - "challengeSeed": [ + "head": [ + "window.exports = function(){};" + ], + "challengeSeed": [ "\"use strict\";", "const foo = \"bar\";", "const boo = \"far\";" @@ -879,7 +889,15 @@ "
", "The code below requires the contents of a file, \"capitalize_strings\", found in the same directory as it, imported. Add the appropriate import * statement to the top of the file, using the object provided." ], - "challengeSeed": [ + "head": [ + "window.require = function(str) {", + "if (str === 'capitalize_strings') {", + "return {", + "capitalize: str => str.toUpperCase(),", + "lowercase: str => str.toLowerCase()", + "}}};" + ], + "challengeSeed": [ "\"use strict\";", "myStringModule.capitalize(\"foo\");", "myStringModule.lowercase(\"Foo\");" @@ -904,7 +922,10 @@ "
", "The following function should be the fallback value for the module. Please add the necessary code to do so." ], - "challengeSeed": [ + "head": [ + "window.exports = function(){};" + ], + "challengeSeed": [ "\"use strict\";", "function subtract(x,y) {return x - y;}" ], @@ -927,7 +948,14 @@ "
", "In the following code, please import the default export, subtract, from the file \"math_functions\", found in the same directory as this file." ], - "challengeSeed": [ + "head": [ + "window.require = function(str) {", + "if (str === 'math_functions') {", + "return function(a, b) {", + "return a - b;", + "}}};" + ], + "challengeSeed": [ "\"use strict\";", "subtract(7,4);" ],