Anonymous Functions Review
Introduction to Higher Order Functions
Testing
Coding Challenge
https://github.com/TelegraphPrep/03-2016-calculator
function (num1, num2) {
return num1 + num2;
};
(function (num1, num2) {
return num1 + num2;
})();
(function (num1, num2) {
return num1 + num2;
})();
(function (num1, num2) {
return num1 + num2;
})();
The function passed in as a parameter is called a CALLBACK
//loops through an array
//and invokes a callback on each element
var loop = function(arr, callback) {
for (var i = 0; i < arr.length; i++) {
callback(arr[i]);
}
};
var loop = function(arr, callback){
for (var i = 0; i < arr.length; i++){
callback(arr[i]);
}
};
// prints an element to the console
var print = function(element){
console.log(element);
};
var arr = ['hi', 'my', 'name', 'is', 'albrey'];
loop(arr, print);
// hi
// my
// name
// is
// albrey
callback!
higher order function
var arr = ['hi', 'my', 'name', 'is', 'albrey'];
loop(arr, function(element) {
console.log(element);
});
// hi
// my
// name
// is
// albrey
callback!
higher order function
Wikipedia says...
Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and ...
That's it for now.
describe('Subtract', function(){
});
First Parameter: a string
Second Parameter: an anonymous function
callback
higher order function
it('it should take two numbers and return the difference', function(){
})
it('it should take two numbers and return the difference', function(){
// create our test case
var subtractTestCase = calculator.subtract(5, 1);
// test it with expect
expect(subtractTestCase).to.be(4);
});
pass test case as argument to expecet
pass expected value as argument to `to.be` method
https://github.com/telegraphprep/testing123