2015-07-07 18:54:27 -07:00
{
2015-08-13 00:21:52 +01:00
"name" : "Object Oriented and Functional Programming" ,
2015-08-15 14:23:10 -07:00
"order" : 0.010 ,
2015-08-11 15:39:07 +01:00
"note" : [
2015-08-12 00:11:56 +01:00
"Waypoint: Closures" ,
"Waypoint: Factories" ,
"Waypoint: Pure Functions" ,
"Waypoint: Currying Functions" ,
"Waypoint: Functors" ,
"Waypoint: Currying Functions"
2015-08-11 15:39:07 +01:00
] ,
2015-07-07 18:54:27 -07:00
"challenges" : [
2015-08-11 15:39:07 +01:00
{
"id" : "cf1111c1c15feddfaeb1bdef" ,
"title" : "Waypoint: A Review On Objects" ,
"difficulty" : 0 ,
"description" : [
2015-08-15 13:57:44 -07:00
"Before we dive into Object Oriented Programming, let's revisit JavaScript objects." ,
"Give your <code>motorBike</code> object the correct attributes."
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"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');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
"//Here is a sample Object" ,
"var car = {" ,
" \"wheels\":4," ,
" \"engine\":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" ,
"};" ,
"" ,
"(function(){return(JSON.stringify(motorBike));})();"
] ,
"challengeType" : 1
} ,
{
"id" : "cf1111c1c15feddfaeb2bdef" ,
"title" : "Waypoint: Constructing Objects" ,
"difficulty" : 0 ,
"description" : [
2015-08-15 13:57:44 -07:00
"We are also able to create objects using functions." ,
""
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
"assert((new Car()).wheels === 4, \"myCar.wheels should be four. Make sure that you haven't changed this value\");" ,
2015-08-14 14:48:59 -07:00
"assert(typeof((new Car()).engine) === 'number', 'myCar.engine should be a number');" ,
"assert(typeof((new Car()).seats) === 'number', 'myCar.seats should be a number');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
2015-08-15 13:57:44 -07:00
"// 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." ,
2015-08-11 15:39:07 +01:00
"var Car = function(){" ,
" this.wheels = 4;" ,
"};" ,
"" ,
"var myCar = new Car();" ,
"" ,
"(function(){return(JSON.stringify(myCar));})();"
] ,
"challengeType" : 1
} ,
{
"id" : "cf1111c1c15feddfaeb3bdef" ,
"title" : "Waypoint: 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"
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"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'), '');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
"//Let's create an object with a two functions. One attached as a property and one not." ,
"var Car = function(){" ,
" this.gear = 1;" ,
" function addStyle(styleMe){" ,
" return('The Current Gear Is: ' + styleMe);" ,
" }" ,
" this.getGear = function(){" ,
" return(addStyle(this.gear));" ,
" };" ,
"};" ,
"" ,
2015-08-12 00:11:56 +01:00
"//Make the function getSpeed of Bike publicly accessible" ,
2015-08-11 15:39:07 +01:00
"" ,
2015-08-12 00:11:56 +01:00
"var Bike = function(){" ,
" speed = 100;" ,
" function addUnit(value){" ,
" return(value + \"KM/H\");" ,
" }" ,
" " ,
" getSpeed = function (){" ,
" return(addUnit(speed));" ,
" };" ,
" " ,
2015-08-11 15:39:07 +01:00
"};" ,
"" ,
"//Instantiated Here" ,
"var myCar = new Car();" ,
2015-08-12 00:11:56 +01:00
"var myBike = new Bike();" ,
2015-08-11 15:39:07 +01:00
"" ,
2015-08-12 00:11:56 +01:00
"if(myBike.hasOwnProperty('getSpeed')){(function(){return(JSON.stringify(myBike.getSpeed()));})();};"
2015-08-11 15:39:07 +01:00
] ,
"challengeType" : 1
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c15feddfaeb4bdef" ,
2015-08-11 15:39:07 +01:00
"title" : "Waypoint: Instantiation" ,
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"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"
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert((new Car()).wheels === 4, 'The property wheels should be four in the object constructor');" ,
"assert(typeof((new Car()).engine) === 'undefined', 'There should not be a property engine in the object constructor');" ,
"assert(myCar.wheels === 4, 'The property wheels of myCar should be four');" ,
"assert(typeof(myCar.engine) === 'number', 'The property engine of myCar should be a number');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
"var Car = function(){" ,
" this.wheels = 4;" ,
"};" ,
"" ,
"var myCar = new Car();" ,
"" ,
"//Add the property engine to myCar using dot notation and make it a number" ,
"" ,
"" ,
"(function(){return(JSON.stringify(myCar));})();"
] ,
"challengeType" : 1
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c15feddfaeb7bdef" ,
"title" : "Waypoint: Using .map" ,
2015-08-11 15:39:07 +01:00
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"<code>array = array.map(function(val){" ,
" return(val+1);" ,
"});</code>" ,
"" ,
"The map method is one of the easiest ways to iterate through an array or object there is. Let's use it now"
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert.deepEqual(array, [4,5,6,7,8], 'You should have added three to each value in the array');" ,
"assert(editor.getValue().match(/\\.map\\(/gi), 'You should be making use of the map method');" ,
"assert(editor.getValue().match(/\\[1\\,2\\,3\\,4\\,5\\]/gi), 'You should only modify the array with .map');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
2015-08-13 00:20:15 +01:00
"//Use map to add three to each value in the array" ,
"var array = [1,2,3,4,5];" ,
"" ,
"" ,
"" ,
"(function(){return(array);})();"
2015-08-11 15:39:07 +01:00
] ,
"challengeType" : 1
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c15feddfaeb8bdef" ,
"title" : "Waypoint: Using .reduce" ,
2015-08-11 15:39:07 +01:00
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"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>"
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert(singleVal == 30, 'singleVal should have been set to the result of you reduce operation');" ,
"assert(editor.getValue().match(/\\.reduce\\(/gi), 'You should have made use of the reduce method');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
2015-08-13 00:20:15 +01:00
"var array = [4,5,6,7,8];" ,
"var singleVal = 0;" ,
"" ,
"" ,
"" ,
"(function(){return(singleVal);})()"
2015-08-11 15:39:07 +01:00
] ,
"challengeType" : 1
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c15feddfaeb9bdef" ,
"title" : "Waypoint: Using .filter" ,
2015-08-11 15:39:07 +01:00
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"" ,
"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>"
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert.deepEqual(array, [1,2,3,4,5], 'You should have removed all the values from the array that are less than six');" ,
"assert(editor.getValue().match(/array\\.filter\\(/gi), 'You should be using the filter method to remove the values from the array');" ,
2015-08-13 00:20:15 +01:00
"assert(editor.getValue().match(/\\[1\\,2\\,3\\,4\\,5\\,6\\,7\\,8\\,9\\,10\\]/gi), 'You should only be using .filter to modify the contents of the array);"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
2015-08-13 00:20:15 +01:00
"var array = [1,2,3,4,5,6,7,8,9,10];" ,
"" ,
"" ,
"" ,
"(function(){return(array);})();"
2015-08-11 15:39:07 +01:00
] ,
"challengeType" : 1
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c16feddfaeb1bdef" ,
"title" : "Waypoint: Using .sort" ,
2015-08-11 15:39:07 +01:00
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"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>" ,
2015-08-14 14:48:59 -07:00
"This will return [1, 2, 3]"
2015-08-11 15:39:07 +01:00
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert.deepEqual(array, ['alpha', 'beta', 'charlie'], 'You should have sorted the array alphabetically');" ,
"assert(editor.getValue().match(/\\[\\'beta\\'\\,\\s\\'alpha\\'\\,\\s'charlie\\'\\];/gi), 'You should be sorting the array using sort');" ,
"assert(editor.getValue().match(/\\.sort\\(\\)/gi), 'You should have made use of the sort method');"
2015-08-11 15:39:07 +01:00
] ,
"challengeSeed" : [
2015-08-13 00:20:15 +01:00
"var array = ['beta', 'alpha', 'charlie'];" ,
"" ,
"" ,
"" ,
"(function(){return(array);})();"
2015-08-11 15:39:07 +01:00
] ,
"challengeType" : 1
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c16feddfaeb2bdef" ,
"title" : "Waypoint: Using .reverse" ,
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"You can use the reverse method to reverse the contents of an array"
2015-08-11 15:39:07 +01:00
] ,
2015-08-12 00:11:56 +01:00
"tests" : [
2015-08-14 14:48:59 -07:00
"assert.deepEqual(array, [7,6,5,4,3,2,1], 'You should reverse the array');" ,
"assert(editor.getValue().match(/\\.reverse\\(\\)/gi), '');" ,
"assert(editor.getValue().match(/\\[1\\,2\\,3\\,4\\,5\\,6\\,7/gi), '');"
2015-08-11 15:39:07 +01:00
] ,
2015-08-12 00:11:56 +01:00
"challengeSeed" : [
2015-08-13 00:20:15 +01:00
"var array = [1,2,3,4,5,6,7];" ,
"" ,
"" ,
"" ,
"(function(){return(array);})();"
2015-08-11 15:39:07 +01:00
] ,
2015-08-12 00:11:56 +01:00
"challengeType" : 1
2015-08-11 15:39:07 +01:00
} ,
{
2015-08-12 00:11:56 +01:00
"id" : "cf1111c1c16feddfaeb3bdef" ,
"title" : "Waypoint: Using .concat" ,
"difficulty" : 0 ,
"description" : [
2015-08-13 00:20:15 +01:00
"Concat can be used to merge the contents of two arrays into one" ,
"<code>array = array.concat(otherArray);</code>"
2015-08-11 15:39:07 +01:00
] ,
2015-08-12 00:11:56 +01:00
"tests" : [
2015-08-14 14:48:59 -07:00
"assert.deepEqual(array, [1,2,3,4,5,6], 'You should concat the two arrays together');" ,
"assert(editor.getValue().match(/\\.concat\\(/gi), 'You should be using the concat method to merge the two arrays');" ,
"assert(editor.getValue().match(/\\[1\\,2\\,3\\]/gi) && editor.getValue().match(/\\[4\\,5\\,6\\]/gi), 'You should only modify the two arrays without changing the origional ones');"
2015-08-11 15:39:07 +01:00
] ,
2015-08-12 00:11:56 +01:00
"challengeSeed" : [
2015-08-13 00:20:15 +01:00
"var array = [1,2,3];" ,
"" ,
"var concatMe = [4,5,6];" ,
"" ,
"" ,
"" ,
"(function(){return(array);})()"
2015-08-11 15:39:07 +01:00
] ,
2015-08-12 00:11:56 +01:00
"challengeType" : 1
2015-08-13 00:20:15 +01:00
} ,
{
"id" : "cf1111c1c16feddfaeb4bdef" ,
"title" : "Waypoint: 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" ,
"<code>array = string.split(' ');</code>"
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert(typeof(array) === 'object' && array.length === 5, 'You should have split the string by it\\'s spaces');" ,
"assert(/\\.split\\(/gi, 'You should have made use of the split method on the string');"
2015-08-13 00:20:15 +01:00
] ,
"challengeSeed" : [
"var string = \"Split me into an array\";" ,
"" ,
"var array = string;" ,
"" ,
"(function(){return(array);})();"
] ,
"challengeType" : 1
} ,
{
"id" : "cf1111c1c16feddfaeb5bdef" ,
"title" : "Waypoint: 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" ,
"<code>var joinMe = joinMe.join(\" \");</code>"
] ,
"tests" : [
2015-08-14 14:48:59 -07:00
"assert(typeof(joinMe) === 'string' && joinMe === \"Split me into an array\", 'You should have joined the arrays by it\\'s spaces');" ,
"assert(/\\.join\\(/gi, 'You should have made use of the join method on the array');"
2015-08-13 00:20:15 +01:00
] ,
"challengeSeed" : [
"var joinMe = [\"Split\",\"me\",\"into\",\"an\",\"array\"];" ,
"" ,
"joinMe = joinMe;" ,
"" ,
"(function(){return(joinMe);})();"
] ,
"challengeType" : 1
2015-08-11 15:39:07 +01:00
}
2015-07-07 18:54:27 -07:00
]
}