The Collection of O(n) and O(1) sorting algorithms
npm install @irbisadm/super-sort --save
# or
yarn add @irbisadm/super-sortIf you have at least nine points of luck, you can use this library without any problems. With general sorting approach, you can sort any array of numbers with superSort function.
The superSort function will select random algorithm from the list of algorithms and sort your array.
import {superSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = await superSort(arr);A terribly inefficient sort algorithm that repeatedly generates a random permutation of the items until the items are in order. It's best complexity is O(n). It's worst complexity is O(∞).
import {bogoSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = bogoSort(arr);A terribly inefficient sort algorithm that randomly swaps items until they are in order. It's best complexity is O(n). It's worst complexity is O(∞).
import {bozoSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = bozoSort(arr);A terribly inefficient sort algorithm that sorts the array by mirraculously putting the items in order. It's best complexity is O(0). It's worst complexity is O(∞).
import {miracleSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = await miracleSort(arr);A terribly inefficient sort algorithm that sorts the array by sleeping for the number of milliseconds proportional to each item in the array. It's best complexity is O(n). It's worst complexity is O(∞).
import {timeSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = await timeSort(arr);A terribly inefficient sort algorithm that sorts the array by eating tacos until the array is sorted. It's best complexity is O(n). It's worst complexity is O(n * 2^32n).
import {tacoSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = tacoSort(arr);A terribly inefficient sort algorithm that sorts the array by removing items that are out of order. It's best complexity is O(1). It's worst complexity is O(1).
import {stalinSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = stalinSort(arr);Most efficient sort algorithm: if the array is already sorted, it will not perform any operations! It's best complexity is O(n). It's worst complexity is O(0).
import {luckySort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = luckySort(arr);A terribly inefficient sort algorithm powered by the invisible hand of the free market: two players meet and the richer one takes a coin from the poorer, so the rich get richer and the poor get poorer, until the market happens to regulate itself into order. It's best complexity is O(n). It's worst complexity is O(∞).
import {capitalismSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = capitalismSort(arr);Pass real: true for real, unregulated capitalism: the invisible hand always ends in monopoly — the
single richest player seizes the entire market and everyone else is left with nothing. Runs in O(n).
import {capitalismSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const monopoly = capitalismSort(arr, 'asc', true); // => [0, 0, 0, 0, 0, 0, 0, 0, 45]Most equal sort algorithm: all wealth is redistributed evenly, so every element becomes the mean and the collective is — by definition — already in perfect order. Direction does not matter: when everyone is equal, there is no up and no down. It's best complexity is O(n). It's worst complexity is O(n).
import {communismSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = communismSort(arr);The most efficient sort algorithm in the multiverse: it shuffles the array exactly once and, if the result is not sorted, it simply destroys the universe. By the many-worlds interpretation, every branch where the array came out unsorted ceases to exist, so in every surviving branch the array is — with certainty — already sorted. It's best complexity is O(n). It's worst complexity is O(n) (the universe is destroyed either way).
import {quantumBogoSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = quantumBogoSort(arr);Perfectly balanced, as all things should be. While the array is out of order, Thanos snaps his fingers and half of the elements turn to dust at random. Eventually the survivors are in order — there may just be fewer of them than the universe started with. It's best complexity is O(n). It's worst complexity is O(n log n).
import {thanosSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = thanosSort(arr);The ultimate act of delegation: instead of sorting anything itself, it hands the whole array to the
Anthropic (Claude) API and trusts whatever comes back. Unlike every other algorithm here, this one is
useless offline — it requires network access and a valid Anthropic API key, which must be passed on
every call (it is never read from the environment). Not part of superSort (it needs a key), so import
it directly.
It's best complexity is O(n). It's worst complexity is O(∞) (rate limits, retries, and the heat death of the API).
import {askClaudeSort} from '@irbisadm/super-sort';
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const sorted = await askClaudeSort(arr, 'asc', process.env.ANTHROPIC_API_KEY);Contributions are welcome — see CONTRIBUTING.md. By participating you agree to our Code of Conduct. Found a security issue? See SECURITY.md.
MIT © Igor Sheko