1.0.3 • Published 5 years ago

median-heap v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

median-heap

get the median of a sequence of numbers

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install median-heap 

API

var Heap = require('median-heap');

var heap = new Heap();
heap.push(1);
heap.push(2);
heap.push(3);

heap.peek();
// => 2

Using a custom comparison function

var Heap = require('median-heap');

var heap = new Heap( function(a,b) {
  return b.age - a.age;
});

var people = [
  { name: 'foo', age: 23},
  { name: 'bar', age: 24},
  { name: 'baz', age: 99}
]

for(var i=0; i < people.length; i++) {
    heap.push(people[i]);
}

heap.peek().name;
// => bar

License

MIT

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago