Skip to content

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