Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(heap): this is undefined #1124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

fix(heap): this is undefined #1124

wants to merge 2 commits into from

Conversation

ojj1123
Copy link

@ojj1123 ojj1123 commented Apr 12, 2024

What's the problem?

  • MaxHeapAdhoc and MinHeapAdhoc constructor can get an array for filling the heap initially.
  • And then the constructors execute this:
this.heap.forEach(this.add);
  • But It did occur this error:
    스크린샷 2024-04-13 01 19 15

  • The problem is that if passing this.add method literally, this used by add method is undefined.

  • This issue is confusing for the developers. And your intend is that MaxHeapAdhoc and MinHeapAdhoc is used by developers easily

#1117

This PR contains several minimalistic (by their functionalities and implementation) data structures like MinHeap, MaxHeap, and DisjointSet that don't have external dependencies and that are easy to copy-paste and use during the coding interview if allowed by the interviewer.

How to fix

  • Just use arrow function
this.heap.forEach((value) => this.add(value));

@ojj1123 ojj1123 changed the title fix(heap): this is undefined fix(heap): this is undefined Apr 12, 2024
@ojj1123
Copy link
Author

ojj1123 commented Apr 17, 2024

@trekhleb
I was wondering if you could review this PR!
I think it is important since your intend could be broken up.

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