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

Crash on basic example #27

Open
newobj opened this issue May 14, 2023 · 1 comment
Open

Crash on basic example #27

newobj opened this issue May 14, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@newobj
Copy link

newobj commented May 14, 2023

const p = new PriorityQueue(function (a, b) {
    return a.value < b.value;
  });
p.push({ text: 'a', value: 2 });
p.push({ text: 'b', value: 7 });
p.push({ text: 'c', value: 4 });
p.push({ text: 'd', value: 1 });
p.push({ text: 'e', value: 8 });
p.push({ text: 'f', value: 1 });
p.pop();
p.pop();
p.pop();
p.pop();

I took the sample comparator code, and added a few pops to the end of the code. This crashes with an undefined value for 'b' being fed into the comparator.

error: Uncaught TypeError: Cannot read properties of undefined (reading 'value')
    return a.value < b.value;
                       ^
    at PriorityQueue._comparator (file:///C:/....ts:78:24)
    at PriorityQueue._compare (file:///C:/Users/newob/AppData/Local/deno/npm/registry.npmjs.org/p-queue-ts/1.2.0/dist/index.js:163:25)
    at PriorityQueue._heapify (file:///C:/Users/newob/AppData/Local/deno/npm/registry.npmjs.org/p-queue-ts/1.2.0/dist/index.js:137:22)
    at PriorityQueue.pop (file:///C:/Users/newob/AppData/Local/deno/npm/registry.npmjs.org/p-queue-ts/1.2.0/dist/index.js:72:14)
    at ... (file:///C:/....ts:90:5)  
@newobj
Copy link
Author

newobj commented May 14, 2023

@davidnguyen11 davidnguyen11 added the bug Something isn't working label May 14, 2023
@davidnguyen11 davidnguyen11 self-assigned this May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants