Skip to content

Commit b1e4cc0

Browse files
committed
Add solution #2666
1 parent 4a44a0c commit b1e4cc0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
2649|[Nested Array Generator](./2649-nested-array-generator.js)|Medium|
392392
2650|[Design Cancellable Function](./2650-design-cancellable-function.js)|Hard|
393393
2665|[Counter II](./2665-counter-ii.js)|Easy|
394+
2666|[Allow One Function Call](./2666-allow-one-function-call.js)|Easy|
394395
2667|[Create Hello World Function](./2667-create-hello-world-function.js)|Easy|
395396
2703|[Return Length of Arguments Passed](./2703-return-length-of-arguments-passed.js)|Easy|
396397
3110|[Score of a String](./3110-score-of-a-string.js)|Easy|
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 2666. Allow One Function Call
3+
* https://leetcode.com/problems/allow-one-function-call/
4+
* Difficulty: Easy
5+
*
6+
* Given a function fn, return a new function that is identical to the original function except
7+
* that it ensures fn is called at most once.
8+
*
9+
* - The first time the returned function is called, it should return the same result as fn.
10+
* - Every subsequent time it is called, it should return undefined.
11+
*/
12+
13+
/**
14+
* @param {Function} fn
15+
* @return {Function}
16+
*/
17+
var once = function(fn) {
18+
return (...args) => fn && [fn(...args), fn = undefined][0];
19+
};

0 commit comments

Comments
 (0)