Skip to content

Commit 7d14947

Browse files
committed
fixing indentation, removing jquery wrappers
1 parent 7308bea commit 7d14947

File tree

3 files changed

+94
-108
lines changed

3 files changed

+94
-108
lines changed
Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,47 @@
11

2-
$(document).ready(function(){
3-
4-
module("About Functions And Closure (topics/about_functions_and_closure.js)");
5-
6-
test("defining functions directly", function() {
7-
var result = "a";
8-
function changeResult() {
9-
// the ability to access a variables defined in the same scope as the function is known as 'closure'
10-
result = "b";
11-
};
12-
changeResult();
13-
equals(result, __, 'what is the value of result?');
14-
});
15-
16-
test("assigning functions to variables", function() {
17-
var triple = function(input) {
18-
return input * 3;
19-
};
20-
equals(triple(4), __, 'what is triple 4?');
21-
});
22-
23-
test("self invoking functions", function() {
24-
var publicValue = "shared";
25-
26-
// self invoking functions are used to provide scoping and to alias variables
27-
(function(pv) {
28-
var secretValue = "password";
29-
equals(pv, __, 'what is the value of pv?');
30-
equals(typeof(secretValue), "__", "is secret value available in this context?");
31-
equals(typeof(pv), "__", "is public value available in this context?");
32-
})(publicValue);
33-
34-
equals(typeof(secretValue), "__", "is secret value available in this context?");
35-
equals(typeof(publicValue), "__", "is public value available in this context?");
36-
});
37-
38-
test("arguments array", function() {
39-
var add = function() {
40-
var total = 0;
41-
for(var i = 0; i < arguments.length; i++) {
42-
// complete the implementation of this method so that it returns the sum of its arguments
43-
}
44-
// __
45-
};
46-
47-
equals(add(1,2,3,4,5), 15, "add 1,2,3,4,5");
48-
equals(add(4,7,-2), 9, "add 1,2,3,4,5");
49-
});
2+
module("About Functions And Closure (topics/about_functions_and_closure.js)");
503

4+
test("defining functions directly", function() {
5+
var result = "a";
6+
function changeResult() {
7+
// the ability to access a variables defined in the same scope as the function is known as 'closure'
8+
result = "b";
9+
};
10+
changeResult();
11+
equals(result, __, 'what is the value of result?');
12+
});
13+
14+
test("assigning functions to variables", function() {
15+
var triple = function(input) {
16+
return input * 3;
17+
};
18+
equals(triple(4), __, 'what is triple 4?');
19+
});
20+
21+
test("self invoking functions", function() {
22+
var publicValue = "shared";
23+
24+
// self invoking functions are used to provide scoping and to alias variables
25+
(function(pv) {
26+
var secretValue = "password";
27+
equals(pv, __, 'what is the value of pv?');
28+
equals(typeof(secretValue), "__", "is secret value available in this context?");
29+
equals(typeof(pv), "__", "is public value available in this context?");
30+
})(publicValue);
31+
32+
equals(typeof(secretValue), "__", "is secret value available in this context?");
33+
equals(typeof(publicValue), "__", "is public value available in this context?");
34+
});
35+
36+
test("arguments array", function() {
37+
var add = function() {
38+
var total = 0;
39+
for(var i = 0; i < arguments.length; i++) {
40+
// complete the implementation of this method so that it returns the sum of its arguments
41+
}
42+
// __
43+
};
44+
45+
equals(add(1,2,3,4,5), 15, "add 1,2,3,4,5");
46+
equals(add(4,7,-2), 9, "add 1,2,3,4,5");
5147
});
Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11

2-
$(document).ready(function(){
2+
module("About Regular Expressions (topics/about_regular_expressions.js)");
33

4-
module("About Regular Expressions (topics/about_regular_expressions.js)");
5-
6-
test("exec", function() {
7-
var numberFinder = /(\d).*(\d)/;
8-
var results = numberFinder.exec("what if 6 turned out to be 9?");
9-
ok(results.equalTo([__, __, __]), 'what is the value of results?');
10-
});
11-
12-
test("test", function() {
13-
var containsSelect = /select/.test(" select * from users ");
14-
equals(containsSelect, __, 'does the string provided contain "select"?');
15-
});
16-
17-
test("match", function() {
18-
var matches = "what if 6 turned out to be 9?".match(/(\d)/g);
19-
ok(matches.equalTo([__, __]), 'what is the value of matches?');
20-
});
21-
22-
test("replace", function() {
23-
var pie = "apple pie".replace("apple", "strawberry");
24-
equals(pie, __, 'what is the value of pie?');
25-
26-
pie = "what if 6 turned out to be 9?".replace(/\d/g, function(number) { // the second parameter can be a string or a function
27-
var map = {'6': 'six','9': 'nine'};
28-
return map[number];
29-
});
30-
equals(pie, __, 'what is the value of pie?');
31-
});
32-
33-
// THE END
34-
4+
test("exec", function() {
5+
var numberFinder = /(\d).*(\d)/;
6+
var results = numberFinder.exec("what if 6 turned out to be 9?");
7+
ok(results.equalTo([__, __, __]), 'what is the value of results?');
358
});
9+
10+
test("test", function() {
11+
var containsSelect = /select/.test(" select * from users ");
12+
equals(containsSelect, __, 'does the string provided contain "select"?');
13+
});
14+
15+
test("match", function() {
16+
var matches = "what if 6 turned out to be 9?".match(/(\d)/g);
17+
ok(matches.equalTo([__, __]), 'what is the value of matches?');
18+
});
19+
20+
test("replace", function() {
21+
var pie = "apple pie".replace("apple", "strawberry");
22+
equals(pie, __, 'what is the value of pie?');
23+
24+
pie = "what if 6 turned out to be 9?".replace(/\d/g, function(number) { // the second parameter can be a string or a function
25+
var map = {'6': 'six','9': 'nine'};
26+
return map[number];
27+
});
28+
equals(pie, __, 'what is the value of pie?');
29+
});
30+
31+
// THE END

topics/about_scope.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11

2-
$(document).ready(function(){
2+
module("About Scope (topics/about_scope.js)");
33

4-
module("About Scope (topics/about_scope.js)");
4+
thisIsAGlobalVariable = 77;
55

6-
thisIsAGlobalVariable = 77;
7-
8-
test("global variables", function() {
9-
equals(thisIsAGlobalVariable, __, 'is thisIsAGlobalVariable defined in this scope?');
10-
});
11-
12-
test("variables declared inside of a function", function() {
13-
var outerVariable = "outer";
6+
test("global variables", function() {
7+
equals(thisIsAGlobalVariable, __, 'is thisIsAGlobalVariable defined in this scope?');
8+
});
9+
10+
test("variables declared inside of a function", function() {
11+
var outerVariable = "outer";
1412

15-
// this is a self-invoking function. Notice that it calls itself at the end ().
16-
(function() {
17-
var innerVariable = "inner";
18-
equals(outerVariable, __, 'is outerVariable defined in this scope?');
19-
equals(innerVariable, __, 'is innerVariable defined in this scope?');
20-
})();
21-
22-
equals(outerVariable, __, 'is outerVariable defined in this scope?');
23-
var isInnerVariableDefined = true;
24-
try {
25-
innerVariable
26-
} catch(e) {
27-
isInnerVariableDefined = false;
28-
}
29-
equals(isInnerVariableDefined, __, 'is innerVariable defined in this scope?');
30-
});
31-
13+
// this is a self-invoking function. Notice that it calls itself at the end ().
14+
(function() {
15+
var innerVariable = "inner";
16+
equals(outerVariable, __, 'is outerVariable defined in this scope?');
17+
equals(innerVariable, __, 'is innerVariable defined in this scope?');
18+
})();
3219

20+
equals(outerVariable, __, 'is outerVariable defined in this scope?');
21+
var isInnerVariableDefined = true;
22+
try {
23+
innerVariable
24+
} catch(e) {
25+
isInnerVariableDefined = false;
26+
}
27+
equals(isInnerVariableDefined, __, 'is innerVariable defined in this scope?');
3328
});
34-

0 commit comments

Comments
 (0)