Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bc0b29

Browse files
committed
2620,2704
1 parent a30b0b4 commit 6bc0b29

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

‎Easy/2620. Counter/solution.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number} n
3+
* @return {Function} counter
4+
*/
5+
var createCounter = function(n) {
6+
7+
return function() {
8+
9+
return n++;
10+
11+
};
12+
};
13+
14+
/**
15+
* const counter = createCounter(10)
16+
* counter() // 10
17+
* counter() // 11
18+
* counter() // 12
19+
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} val
3+
* @return {Object}
4+
*/
5+
var expect = function (val) {
6+
return {
7+
toBe: function (expected) {
8+
return val === expected;
9+
},
10+
notToBe: function (expected) {
11+
if (val === expected) {
12+
throw new Error("Equal");
13+
}
14+
}
15+
};
16+
};
17+
18+
/**
19+
* expect(5).toBe(5); // true
20+
* expect(5).notToBe(5); // throws "Equal"
21+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /