Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

floyd-rivest

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

floyd-rivest

The Floyd-Rivest k-smallest selection algorithm.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

floyd-rivest

A typescript implementation of the Floyd-Rivest selection algorithm.

This module exports a single function, select<T>(array: T[], k: number, compare?: (a: T, b: T) => number) => T implementing the Floyd-Rivest selection algorithm. select returns the k-smallest element of the input array, and mutates the array to ensure that the k-smallest element is at index k-1, all items at indices < (k-1) are less than or equal to array[k-1] and all items at indices > (k-1) are greater than or equal to array[k-1]. Elements are not sorted within each partition.

Usage

const { select } = require('floyd-rivest');
const array = [1,6,2,3,9,4,7,2,7,0,5];
const e = select(array, 3); // e = 2, the third-smallest element of the array
const ksmallest = array.slice(0,3); // ksmallest contains [0, 1, 2], not necessarily in that order

Keywords

FAQs

Package last updated on 03 Nov 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc