Skip to content

Commit 726b00e

Browse files
authored
Create 2666-allow-one-function-call.js
1 parent c071774 commit 726b00e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {Function} fn
3+
* @return {Function}
4+
*/
5+
var once = function (fn) {
6+
let called = false;
7+
return function (...args) {
8+
if (!called) {
9+
called = true;
10+
return fn(...args);
11+
}
12+
}
13+
};
14+
15+
/**
16+
* let fn = (a,b,c) => (a + b + c)
17+
* let onceFn = once(fn)
18+
*
19+
* onceFn(1,2,3); // 6
20+
* onceFn(2,3,6); // returns undefined without calling fn
21+
*/

0 commit comments

Comments
 (0)