forked from edgecoder/tdd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (34 loc) · 1.1 KB
/
index.js
File metadata and controls
45 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var doubler = function(a, b) {
if (typeof a === "function") {
return a() + a() + b() + b();
} else if (typeof a === "object") {
return a.x1 + a.x1 + a.x2 + a.x2
} else {
return a + a + b + b
}
}
console.assert(doubler(4,2) ===12);
console.assert(doubler(1,3) ===8);
console.assert(doubler(-1,3) ===4);
console.assert(doubler("a", "b") === "aabb");
console.assert(doubler("coding", "rocks") === "codingcodingrocksrocks");
function m3() { return 3; }
function m4() { return 4; }
function m2() { return 2; }
function m1() { return 1; }
console.assert(doubler(m4, m2) === 12);
console.assert(doubler(m1, m3) === 8);
function m3() { return 3; }
function m4() { return 4; }
function m2() { return 2; }
function m1() { return 1; }
console.assert(doubler(m4, m2) === 12);
console.assert(doubler(m1, m3) === 8);
function objectsEqual(a , b) {
return a.z + a.t === b.t + b.z
}
var a = { z: 42 , t: 7 }, b = { t: 7, z: 42 }
console.assert(objectsEqual(a, b));
console.assert(objectsEqual(b, a));
objectsEqual(doubler({x1: 1, x2: 4}), {x1: 2, x2: 8});
objectsEqual(doubler({x1: -4, x2: 0}), {x1: -8, x2: 0});