Skip to content

Commit 84d9acd

Browse files
authored
Update README_EN.md
1 parent 9b4f00b commit 84d9acd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

solution/2600-2699/2666.Allow One Function Call/README_EN.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ onceFn(4, 6, 8); // undefined, fn was not called
6868
#### TypeScript
6969

7070
```ts
71-
function once<T extends (...args: any[]) => any>(
72-
fn: T,
73-
): (...args: Parameters<T>) => ReturnType<T> | undefined {
71+
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
72+
type OnceFn = (...args: JSONValue[]) => JSONValue | undefined;
73+
74+
function once(fn: Function): OnceFn {
7475
let called = false;
7576
return function (...args) {
7677
if (!called) {
@@ -89,22 +90,21 @@ function once<T extends (...args: any[]) => any>(
8990
*/
9091
```
9192

92-
<!-- tabs:end -->
93+
#### JavaScript
9394

9495
```js
9596
/**
9697
* @param {Function} fn
9798
* @return {Function}
9899
*/
99-
var once = function(fn) {
100+
var once = function (fn) {
100101
let called = false;
101-
return function(...args){
102-
if(!called){
103-
called=true;
102+
return function (...args) {
103+
if (!called) {
104+
called = true;
104105
return fn(...args);
105106
}
106-
return undefined;
107-
}
107+
};
108108
};
109109

110110
/**
@@ -114,9 +114,10 @@ var once = function(fn) {
114114
* onceFn(1,2,3); // 6
115115
* onceFn(2,3,6); // returns undefined without calling fn
116116
*/
117+
```
117118

119+
<!-- tabs:end -->
118120

119121
<!-- solution:end -->
120122

121123
<!-- problem:end -->
122-
```

0 commit comments

Comments
 (0)