zandaqo / structurae

Data structures for high-performance JavaScript applications.
MIT License
694 stars 21 forks source link

Documentation: BinaryHeap.compare #18

Closed hungarian-notation closed 3 years ago

hungarian-notation commented 3 years ago

The documentation gives an example alternative compare function for as:

const { BinaryHeap } = require('structurae');

class MaxHeap extends BinaryHeap {}
MaxHeap.compare = (a, b) => b - a; 

This example will not compile in a typescript project, as BinaryHeap.compare has the signature:

static compare(a: any, b: any): boolean;

It appears that the implementation does indeed expect a boolean result from compare, and as such the documentation should probably be something like:

const { BinaryHeap } = require('structurae');

class MaxHeap extends BinaryHeap {}
MaxHeap.compare = (a, b) => a > b; 
zandaqo commented 3 years ago

Yes, indeed BineryHeap#compare returns a boolean. Thanks!