median-heap
v1.0.3
Published
online algorithm to get the median of a sequence of numbers
Downloads
5
Maintainers
Readme
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