New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hifo

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hifo

Remembers the highest/lowest values in a data set of any size.

1.0.0
latest
Source
npm
Version published
Weekly downloads
90
-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

hifo – highest in, first out ⚖

Remembers the highest/lowest values in a data set of any size. Useful if you have a large number of values, but are only interested in the n highest (or lowest) ones. If you looking for a stream version, check out hifo-stream.

  • hifo is fast. To find the highest m of n values, the time complexity is O(m * n).
  • It is memory-efficient. If you specifiy its size as 50, it will only store 50 values in memory.
  • hifo works with numeric values and simple objects out of the box, but you can pass your own sort function.

build status npm version dependency status dev dependency status ISC-licensed chat on gitter support me on Patreon

Example

Let's assume we have a huge array of people.

var people = [
	{ name: 'Alice', age: 23 },
	{ name: 'Eve', age: 45 },
	{ name: 'Jane', age: 19 },
	{ name: 'Bob', age: 30 },
	{ name: 'John', age: 60 },
	// thousands of others
];

To find the 3 oldest people, we reate a new Hifo instance and pass the 'age' as the filter key and 3 as the size.

var hifo = require('hifo');

var oldest = hifo(hifo.highest('age'), 3);
for (var person in people) {
	oldest.add(person);
}

oldest.data will now look like this:

[
	{ name: 'John', age: 60 },
	{ name: 'Eve', age: 45 },
	{ name: 'Bob', age: 30 }
]

Of course you can do this kind of filtering with hifo.lowest as well.

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

Keywords

sort

FAQs

Package last updated on 07 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts