median-heap

1.0.3 • Public • Published

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

Package Sidebar

Install

npm i median-heap

Weekly Downloads

7

Version

1.0.3

License

MIT

Unpacked Size

6.23 kB

Total Files

5

Last publish

Collaborators

  • rylans