Concepts

Three-way quicksort

Try the free JavaScript compiler

Partition into values smaller than, equal to, and larger than a pivot, then sort the outer groups. Work depends on pivot balance.

Formal Syntax & Structure

javascript syntaxjavascript
quickSort(values) → sorted copy

Working Example

Example Snippetjavascript
const a=[4,1,4,8,2],pivot=4;const groups=[a.filter(x=>x<pivot),a.filter(x=>x===pivot),a.filter(x=>x>pivot)];console.log(JSON.stringify(groups));
JavaScript Reference