Skip to content

Commit 5c47a2e

Browse files
committed
Change flag after call
1 parent 709a21a commit 5c47a2e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

JavaScript/6-wrap-once.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const once = (fn) => {
66
let finished = false;
77
return (...args) => {
88
if (finished) return;
9+
const res = fn(...args);
910
finished = true;
10-
fn(...args);
11+
return res;
1112
};
1213
};
1314

JavaScript/7-wrap-count.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
const limit = (count, fn) => {
66
let counter = 0;
77
return (...args) => {
8-
if (counter++ === count) return;
9-
fn(...args);
8+
if (counter === count) return;
9+
const res = fn(...args);
10+
counter++;
11+
return res;
1012
};
1113
};
1214

0 commit comments

Comments
 (0)