Skip to content

add task solution#342

Open
timurradkevic wants to merge 3 commits into
mate-academy:masterfrom
timurradkevic:develop
Open

add task solution#342
timurradkevic wants to merge 3 commits into
mate-academy:masterfrom
timurradkevic:develop

Conversation

@timurradkevic

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

The provided response contains non-JSON text and does not match the expected schema. The JSON must only contain a valid object with 'decision' (string, either 'APPROVE' or 'REQUEST_CHANGES') and 'reason' (string) fields.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/MyEventEmitter.js
Comment on lines +35 to +38
emit(key, ...args) {
for (const listener of this.#events[key]) {
listener(...args);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emit method iterates over this.#events[key] without checking if the array exists. When key doesn't exist in #events, this evaluates to undefined and throws a TypeError. The task requires handling the edge case of emitting an event with no listeners registered - it should simply do nothing.

Comment thread src/MyEventEmitter.js Outdated
Comment on lines +60 to +61
removeAllListeners(event) {
this.#events[event] = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removeAllListeners method assigns an empty array to this.#events[event]. When called without arguments, event is undefined, so only this.#events[undefined] gets cleared. The task requires removing all listeners for all events when no event is specified. You need to check if event is provided and either clear all events or just the specified one.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Your implementation passes all requirements. All 8 methods (on, once, off, emit, prependListener, prependOnceListener, removeAllListeners, and listenerCount) are working correctly, edge cases are handled properly, and there are no functional issues. As a minor improvement, the listenerCount method could be simplified from using reduce to return this.#events[event]?.length ?? 0, but your current implementation works correctly. This is purely optional—a stylistic suggestion rather than a required change. Great work on a clean, dependency-free implementation using modern JavaScript private fields.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread src/MyEventEmitter.js Outdated
Comment on lines +71 to +73
listenerCount(event) {
if (Array.isArray(this.#events[event])) {
return this.#events[event].reduce((acc) => (acc += 1), 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The listenerCount method uses reduce to count items, but JavaScript arrays have a built-in .length property that's more idiomatic and efficient. Consider using return this.#events[event]?.length ?? 0 for a cleaner implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants