1. quickselect
A tiny and fast selection algorithm in JavaScript.
quickselect
Package: quickselect
Last modified: Sat, 25 Jun 2022 07:26:51 GMT
Version: 2.0.0
License: ISC
Downloads: 8,381,400

Install

npm install quickselect
yarn add quickselect

quickselect Build Status

A tiny and fast selection algorithm in JavaScript
(specifically, Floyd-Rivest selection).

 quickselect(array, k[, left, right, compareFn]);

Rearranges items so that all items in the [left, k] are the smallest.
The k-th element will have the (k - left + 1)-th smallest value in [left, right].

  • array: the array to partially sort (in place)
  • k: middle index for partial sorting (as defined above)
  • left: left index of the range to sort (0 by default)
  • right: right index (last index of the array by default)
  • compareFn: compare function

Example:

 var arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39];

quickselect(arr, 8);

// arr is [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95]
//                                         ^^ middle index

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code