Bogosort, also known as Monkeysort or Stupidsort is a quite simple sorting algorithm rarely used in production.
The idea is to shuffle a collection as long as it is not sorted.
// Input: Arraywhile !
// Input: Array of length nfor i from n − 1 to 1 doj = random from 0 to iexchange aj and ai
Bogosort is exposed via Universal Module Definition (UMD). Thus, you can use it in your browser, in a require.js environment as well as in node or any bundled project. At also comes with a minified version and a source map.
Bogosort exposes a function
bogosort() that takes an array of numbers and returns a sorted copy of it. The original array
will not be mutated.
var bogosort = ;var sorted = ;
bogosort() function also has a function property
bogosort.measure() that returns an object containing
the sorted collection as well as number of rounds it took to sort it.
var bogosort = ;var sorted = bogosort;console;console;
The example.js file contains an example of that.
To build it yourself just checkout the repository and run
All important commands are run using
# Run testsnpm test# Run the examplenpm start# Build the minified versionnpm run build