improvements to javascript challenges
This commit is contained in:
@@ -2,84 +2,93 @@
|
||||
"name": "Object Oriented and Functional Programming",
|
||||
"order": 0.010,
|
||||
"note": [
|
||||
"Waypoint: Closures",
|
||||
"Waypoint: Factories",
|
||||
"Waypoint: Pure Functions",
|
||||
"Waypoint: Currying Functions",
|
||||
"Waypoint: Functors",
|
||||
"Waypoint: Currying Functions"
|
||||
"Closures",
|
||||
"Factories",
|
||||
"Pure Functions",
|
||||
"Currying Functions",
|
||||
"Functors",
|
||||
"Currying Functions"
|
||||
],
|
||||
"challenges": [
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb1bdef",
|
||||
"title":"Waypoint: A Review On Objects",
|
||||
"title": "Declaring JavaScript Objects as Variables",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Before we dive into Object Oriented Programming, let's revisit JavaScript objects.",
|
||||
"Give your <code>motorBike</code> object the correct attributes."
|
||||
"Give your <code>motorBike</code> object a <code>wheels</code>, <code>engine</code> and <code>seats</code> attribute and set them to numbers."
|
||||
],
|
||||
"tests":[
|
||||
"assert(motorBike.wheels===2, 'You should have given motorBike two wheels');",
|
||||
"assert(motorBike.engine===1, 'You should have given motorBike one engine');",
|
||||
"assert(motorBike.seats===1, 'You should have given motorBike one seat');"
|
||||
"assert(typeof(motorBike.engines) === 'number', '<code>engines</code> should be have a <code>engines</code> attribute set to a number.');",
|
||||
"assert(typeof(motorBike.wheels) === 'number', '<code>wheels</code> should be have a <code>engines</code> attribute set to a number.');",
|
||||
"assert(typeof(motorBike.seats) === 'number', '<code>seats</code> should be have a <code>engines</code> attribute set to a number.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"//Here is a sample Object",
|
||||
"var car = {",
|
||||
" \"wheels\":4,",
|
||||
" \"engine\":1,",
|
||||
" \"seats\":5",
|
||||
" \"wheels\":4,",
|
||||
" \"engines\":1,",
|
||||
" \"seats\":5",
|
||||
"};",
|
||||
"",
|
||||
"//Now Let's make a similar Object called motorBike",
|
||||
"//Give it two wheels, one engine and one seat",
|
||||
"var motorBike = {",
|
||||
" \"wheels\":0,",
|
||||
" \"engine\":0,",
|
||||
" \"seats\":0",
|
||||
" // Only change code below this line.",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" // Only change code above this line.",
|
||||
"};",
|
||||
"",
|
||||
"(function(){return(JSON.stringify(motorBike));})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint",
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb2bdef",
|
||||
"title":"Waypoint: Constructing Objects",
|
||||
"title": "Constructing JavaScript Objects with Functions",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"We are also able to create objects using functions.",
|
||||
""
|
||||
"We are also able to create objects using <code>constructor</code> functions.",
|
||||
"Give your <code>motorBike</code> object a <code>wheels</code>, <code>engine</code> and <code>seats</code> attribute and set them to numbers."
|
||||
],
|
||||
"tests":[
|
||||
"assert((new Car()).wheels === 4, \"myCar.wheels should be four. Make sure that you haven't changed this value\");",
|
||||
"assert(typeof((new Car()).engine) === 'number', 'myCar.engine should be a number');",
|
||||
"assert(typeof((new Car()).seats) === 'number', 'myCar.seats should be a number');"
|
||||
"assert(typeof((new Car()).engines) === 'number', '<code>engines</code> should be have a <code>engines</code> attribute set to a number.');",
|
||||
"assert(typeof((new Car()).wheels) === 'number', '<code>wheels</code> should be have a <code>engines</code> attribute set to a number.');",
|
||||
"assert(typeof((new Car()).seats) === 'number', '<code>seats</code> should be have a <code>engines</code> attribute set to a number.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"// Let's add the properties engine and seats to the car in the same way that the property wheels has been added below. They should both be numbers.",
|
||||
"var Car = function(){",
|
||||
" this.wheels = 4;",
|
||||
" // Only change code below this line.",
|
||||
" this.wheels = 4;",
|
||||
" this.engines = 1;",
|
||||
" this.seats = 1;",
|
||||
"};",
|
||||
"",
|
||||
"var myCar = new Car();",
|
||||
"var motorBike = new Car();",
|
||||
"// Only change code above this line.",
|
||||
"",
|
||||
"(function(){return(JSON.stringify(myCar));})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb3bdef",
|
||||
"title":"Waypoint: Understanding Public and Private Properties",
|
||||
"title":"Understanding Public and Private Properties",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"In the last challenge we use the <code>this</code> to reference public properties the current object or function.",
|
||||
"We can also create variables and functions that aren't accessible from outside the Object"
|
||||
"We can also create variables and functions that aren't accessible from outside the object."
|
||||
],
|
||||
"tests":[
|
||||
"assert(typeof(myBike.getSpeed)!=='undefined' && typeof(myBike.getSpeed) === 'function', 'The method getSpeed of myBike should be accessible outside the Object');",
|
||||
"assert(typeof(myBike.speed) === 'undefined', 'We should not been able');",
|
||||
"assert(typeof(myBike.addUnit === 'undefined'), '');"
|
||||
"assert(typeof(myBike.getSpeed)!=='undefined' && typeof(myBike.getSpeed) === 'function', 'The method getSpeed of myBike should be accessible outside the object');",
|
||||
"assert(typeof(myBike.speed) === 'undefined', '<code>myBike.speed</code> should remain undefined.');",
|
||||
"assert(typeof(myBike.addUnit === 'undefined'), '<code>myBike.addUnit</code> should remain undefined.');"
|
||||
],
|
||||
"challengeSeed":[
|
||||
"//Let's create an object with a two functions. One attached as a property and one not.",
|
||||
@@ -113,15 +122,16 @@
|
||||
"",
|
||||
"if(myBike.hasOwnProperty('getSpeed')){(function(){return(JSON.stringify(myBike.getSpeed()));})();};"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb4bdef",
|
||||
"title":"Waypoint: Instantiation",
|
||||
"title":"Instantiation",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Instantiation at it's most basic level is where you are creating a copy of an object from a template for use at a later time",
|
||||
"The instance inherits all the properties and methods of the original Object"
|
||||
"Instantiation at it's most basic level is where you are creating a copy of an object from a template for use at a later time.",
|
||||
"The instance inherits all the properties and methods of the original Object."
|
||||
],
|
||||
"tests":[
|
||||
"assert((new Car()).wheels === 4, 'The property wheels should be four in the object constructor');",
|
||||
@@ -141,18 +151,19 @@
|
||||
"",
|
||||
"(function(){return(JSON.stringify(myCar));})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb7bdef",
|
||||
"title":"Waypoint: Using .map",
|
||||
"title":"Using .map",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"<code>array = array.map(function(val){",
|
||||
" return(val+1);",
|
||||
"});</code>",
|
||||
"<code>array = array.map(function(val){</code>",
|
||||
"<code>thinsp;thinsp;return(val+1);</code>",
|
||||
"<code>});</code>",
|
||||
"",
|
||||
"The map method is one of the easiest ways to iterate through an array or object there is. Let's use it now"
|
||||
"The map method is one of the easiest ways to iterate through an array or object there is. Let's use it now."
|
||||
],
|
||||
"tests":[
|
||||
"assert.deepEqual(array, [4,5,6,7,8], 'You should have added three to each value in the array');",
|
||||
@@ -167,17 +178,18 @@
|
||||
"",
|
||||
"(function(){return(array);})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb8bdef",
|
||||
"title":"Waypoint: Using .reduce",
|
||||
"title":"Using .reduce",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"Reduce can be useful for condensing and array or numbers into one value.",
|
||||
"<code>var singleVal = array.reduce(function(previousVal, currentVal){",
|
||||
" return(previousVal+currentVal);",
|
||||
"}</code>"
|
||||
"<code>var singleVal = array.reduce(function(previousVal, currentVal){</code>",
|
||||
"<code>thinsp;thinsp;return(previousVal+currentVal);</code>",
|
||||
"<code>}</code>"
|
||||
],
|
||||
"tests":[
|
||||
"assert(singleVal == 30, 'singleVal should have been set to the result of you reduce operation');",
|
||||
@@ -191,19 +203,19 @@
|
||||
"",
|
||||
"(function(){return(singleVal);})()"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c15feddfaeb9bdef",
|
||||
"title":"Waypoint: Using .filter",
|
||||
"title":"Using .filter",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"",
|
||||
"filter is a useful method that can filter out values that don't match a certain criteria",
|
||||
"Let's remove all the values less than six",
|
||||
"<code>array = array.filter(function(val){",
|
||||
" return(val<4);",
|
||||
"});</code>"
|
||||
"<code>array = array.filter(function(val) {</code>",
|
||||
"<code>thinsp;thinsp;return(val<4);</code>",
|
||||
"<code>});</code>"
|
||||
],
|
||||
"tests":[
|
||||
"assert.deepEqual(array, [1,2,3,4,5], 'You should have removed all the values from the array that are less than six');",
|
||||
@@ -217,17 +229,18 @@
|
||||
"",
|
||||
"(function(){return(array);})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c16feddfaeb1bdef",
|
||||
"title":"Waypoint: Using .sort",
|
||||
"title":"Using .sort",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"You can use the method sort to easily sort the values in the array alphabetically or numerically",
|
||||
"<code>var array = [1,3,2];",
|
||||
"array = array.sort();</code>",
|
||||
"This will return [1, 2, 3]"
|
||||
"<code>var array = [1,3,2];</code>",
|
||||
"<code>array = array.sort();</code>",
|
||||
"This will return <code>[1, 2, 3]</code>"
|
||||
],
|
||||
"tests":[
|
||||
"assert.deepEqual(array, ['alpha', 'beta', 'charlie'], 'You should have sorted the array alphabetically');",
|
||||
@@ -241,14 +254,15 @@
|
||||
"",
|
||||
"(function(){return(array);})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id": "cf1111c1c16feddfaeb2bdef",
|
||||
"title": "Waypoint: Using .reverse",
|
||||
"title": "Using .reverse",
|
||||
"difficulty": 0,
|
||||
"description": [
|
||||
"You can use the reverse method to reverse the contents of an array"
|
||||
"You can use the <code>.reverse()</code> function to reverse the contents of an array."
|
||||
],
|
||||
"tests": [
|
||||
"assert.deepEqual(array, [7,6,5,4,3,2,1], 'You should reverse the array');",
|
||||
@@ -262,14 +276,15 @@
|
||||
"",
|
||||
"(function(){return(array);})();"
|
||||
],
|
||||
"challengeType": 1
|
||||
"challengeType": 1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id": "cf1111c1c16feddfaeb3bdef",
|
||||
"title": "Waypoint: Using .concat",
|
||||
"title": "Using .concat",
|
||||
"difficulty": 0,
|
||||
"description": [
|
||||
"Concat can be used to merge the contents of two arrays into one",
|
||||
"<code>.concat()</code> can be used to merge the contents of two arrays into one.",
|
||||
"<code>array = array.concat(otherArray);</code>"
|
||||
],
|
||||
"tests": [
|
||||
@@ -286,16 +301,16 @@
|
||||
"",
|
||||
"(function(){return(array);})()"
|
||||
],
|
||||
"challengeType": 1
|
||||
"challengeType": 1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c16feddfaeb4bdef",
|
||||
"title":"Waypoint: Using .split",
|
||||
"title":"Using .split",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"",
|
||||
"You can use the split method to split a string into an array",
|
||||
"split uses the argument you give to to split the string",
|
||||
"You can use the <code>.split()</code> method to split a string into an array.",
|
||||
"split uses the argument you give to to split the string.",
|
||||
"<code>array = string.split(' ');</code>"
|
||||
],
|
||||
"tests":[
|
||||
@@ -309,14 +324,15 @@
|
||||
"",
|
||||
"(function(){return(array);})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
},
|
||||
{
|
||||
"id":"cf1111c1c16feddfaeb5bdef",
|
||||
"title":"Waypoint: Using .join",
|
||||
"title":"Using .join",
|
||||
"difficulty":0,
|
||||
"description":[
|
||||
"We can use the join method to join each element in an array into a string separated by whatever delimiter you provide as an argument to the join operation",
|
||||
"We can use the <code>.join()</code> method to join each element in an array into a string separated by whatever delimiter you provide as an argument to the join operation.",
|
||||
"<code>var joinMe = joinMe.join(\" \");</code>"
|
||||
],
|
||||
"tests":[
|
||||
@@ -330,7 +346,8 @@
|
||||
"",
|
||||
"(function(){return(joinMe);})();"
|
||||
],
|
||||
"challengeType":1
|
||||
"challengeType":1,
|
||||
"type": "waypoint"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user