Skip to content

Commit 7f9a1e2

Browse files
committed
up
1 parent 37241b6 commit 7f9a1e2

22 files changed

+295
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function makeCounter() {
2+
let count = 0;
3+
4+
function counter() {
5+
return count++;
6+
}
7+
8+
counter.set = value => count = value;
9+
10+
counter.decrease = () => count--;
11+
12+
return counter;
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function makeCounter() {
2+
let count = 0;
3+
4+
// ... your code ...
5+
}
6+
7+
let counter = makeCounter();
8+
9+
alert( counter() ); // 0
10+
alert( counter() ); // 1
11+
12+
counter.set(10); // set the new count
13+
14+
alert( counter() ); // 10
15+
16+
counter.decrease(); // decrease the count by 1
17+
18+
alert( counter() ); // 10 (instead of 11)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
describe("counter", function() {
2+
3+
it("increases from call to call", function() {
4+
5+
let counter = makeCounter();
6+
7+
assert.equal( counter(), 0 );
8+
assert.equal( counter(), 1 );
9+
assert.equal( counter(), 2 );
10+
});
11+
12+
13+
describe("counter.set", function() {
14+
it("sets the count", function() {
15+
16+
let counter = makeCounter();
17+
18+
counter.set(10);
19+
20+
assert.equal( counter(), 10 );
21+
assert.equal( counter(), 11 );
22+
});
23+
});
24+
25+
describe("counter.decrease", function() {
26+
it("decreases the count", function() {
27+
28+
let counter = makeCounter();
29+
30+
counter.set(10);
31+
32+
assert.equal( counter(), 10 );
33+
34+
counter.decrease();
35+
36+
assert.equal( counter(), 10 );
37+
38+
});
39+
});
40+
41+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function makeCounter() {
2+
let count = 0;
3+
4+
function counter() {
5+
return count++;
6+
}
7+
8+
counter.set = value => count = value;
9+
10+
counter.decrease = () => count--;
11+
12+
return counter;
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function makeCounter() {
2+
let count = 0;
3+
4+
// ... your code ...
5+
}
6+
7+
let counter = makeCounter();
8+
9+
alert( counter() ); // 0
10+
alert( counter() ); // 1
11+
12+
counter.set(10); // set the new count
13+
14+
alert( counter() ); // 10
15+
16+
counter.decrease(); // decrease the count by 1
17+
18+
alert( counter() ); // 10 (instead of 11)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Concatenate typed arrays
3+
4+
Given multiple `chunks`, concatenate them into a single typed array.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
describe("counter", function() {
2+
3+
it("increases from call to call", function() {
4+
5+
let counter = makeCounter();
6+
7+
assert.equal( counter(), 0 );
8+
assert.equal( counter(), 1 );
9+
assert.equal( counter(), 2 );
10+
});
11+
12+
13+
describe("counter.set", function() {
14+
it("sets the count", function() {
15+
16+
let counter = makeCounter();
17+
18+
counter.set(10);
19+
20+
assert.equal( counter(), 10 );
21+
assert.equal( counter(), 11 );
22+
});
23+
});
24+
25+
describe("counter.decrease", function() {
26+
it("decreases the count", function() {
27+
28+
let counter = makeCounter();
29+
30+
counter.set(10);
31+
32+
assert.equal( counter(), 10 );
33+
34+
counter.decrease();
35+
36+
assert.equal( counter(), 10 );
37+
38+
});
39+
});
40+
41+
});
3.19 KB
Loading
6.83 KB
Loading
3.15 KB
Loading

0 commit comments

Comments
 (0)