mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
存量题库数据更新
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> actions = ["EventEmitter", "emit", "subscribe", "subscribe", "emit"], values = [[], ["firstEvent", "function cb1() { return 5; }"], ["firstEvent", "function cb1() { return 5; }"], ["firstEvent"]]
|
||||
<strong>Input:</strong>
|
||||
actions = ["EventEmitter", "emit", "subscribe", "subscribe", "emit"],
|
||||
values = [[], ["firstEvent", "function cb1() { return 5; }"], ["firstEvent", "function cb1() { return 6; }"], ["firstEvent"]]
|
||||
<strong>Output:</strong> [[],["emitted",[]],["subscribed"],["subscribed"],["emitted",[5,6]]]
|
||||
<strong>Explanation:</strong>
|
||||
const emitter = new EventEmitter();
|
||||
@@ -26,9 +28,11 @@ emitter.emit("firstEvent"); // [5, 6], returns the output of cb1 and c
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> actions = ["EventEmitter", "subscribe", "emit", "emit"], values = [[], ["firstEvent", "function cb1(...args) { return args.join(','); }"], ["firstEvent", [1,2,3]], ["firstEvent", [3,4,6]]]
|
||||
<strong>Input:</strong>
|
||||
actions = ["EventEmitter", "subscribe", "emit", "emit"],
|
||||
values = [[], ["firstEvent", "function cb1(...args) { return args.join(','); }"], ["firstEvent", [1,2,3]], ["firstEvent", [3,4,6]]]
|
||||
<strong>Output:</strong> [[],["subscribed"],["emitted",["1,2,3"]],["emitted",["3,4,6"]]]
|
||||
<strong>Explanation: </strong>Note that the emit method should be able to accept an OPTIONAL array of arguents.
|
||||
<strong>Explanation: </strong>Note that the emit method should be able to accept an OPTIONAL array of arguments.
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
emitter.subscribe("firstEvent, function cb1(...args) { return args.join(','); });
|
||||
@@ -39,7 +43,9 @@ emitter.emit("firstEvent", [3, 4, 6]); // ["3,4,6"]
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> actions = ["EventEmitter", "subscribe", "emit", "unsubscribe", "emit"], values = [[], ["firstEvent", "(...args) => args.join(',')"], ["firstEvent", [1,2,3]], [0], ["firstEvent", [4,5,6]]]
|
||||
<strong>Input:</strong>
|
||||
actions = ["EventEmitter", "subscribe", "emit", "unsubscribe", "emit"],
|
||||
values = [[], ["firstEvent", "(...args) => args.join(',')"], ["firstEvent", [1,2,3]], [0], ["firstEvent", [4,5,6]]]
|
||||
<strong>Output:</strong> [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[]]]
|
||||
<strong>Explanation:</strong>
|
||||
const emitter = new EventEmitter();
|
||||
@@ -49,6 +55,20 @@ sub.unsubscribe(); // undefined
|
||||
emitter.emit("firstEvent", [4, 5, 6]); // [], there are no subscriptions
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
actions = ["EventEmitter", "subscribe", "subscribe", "unsubscribe", "emit"],
|
||||
values = [[], ["firstEvent", "x => x + 1"], ["firstEvent", "x => x + 2"], [0], ["firstEvent", [5]]]
|
||||
<strong>Output:</strong> [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[7]]]
|
||||
<strong>Explanation:</strong>
|
||||
const emitter = new EventEmitter();
|
||||
const sub1 = emitter.subscribe("firstEvent", x => x + 1);
|
||||
const sub2 = emitter.subscribe("firstEvent", x => x + 2);
|
||||
sub1.unsubscribe(); // undefined
|
||||
emitter.emit("firstEvent", [5]); // [7]</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
|
Reference in New Issue
Block a user