npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@yoloftw/bad-sorting

v1.0.0

Published

All the worst ways to sort arrays

Downloads

1

Readme

Status GitHub Issues GitHub Pull Requests License


Table of Contents

About

Tired of your wimpy sorting algorithms getting the job done too darn fast? Or maybe you're fed up of reaching for that elusive O(1) algorithim. Well you should try Bad-Sorting! the npm package for those who like their sorts served with the heat death of the universe!

This glorious collection of terrible, horrible, no good, very bad sorting techniques (affectionately called "algorithms") is guaranteed to modify your data. For better or for worse

Why Bad-Sorting?

  • Because why not? Normality is so boring.
  • Need a good laugh? Watch your CPU cry as it wrestles with bogosort.
  • Busy day? Multi-Task as your computer sleep sorts!

Installing

For Installation With NPM

npm i @yoloftw/bad-sorting

Usage

Sure, you installed Bad-Sorting, but how do you use it? Don't worry, I've got you covered.

First things first you've got pick your poison and import it into your project.

const { BogoSort } = require('@yoloftw/Bad-Sorting');

The next step is to question your life choises that brought you to this moment in time.

Last but not least SORT

let arr = [7, 2, 20, 5, 15, 3];

let sorted = BogoSort(arr);

console.log(sorted);
//expected output: [2, 3, 5, 7, 15, 20]

Bogo Sort

Ah, Bogo Sort, the algorithm that embodies the spirit of "throw it at the wall and see if it sticks. Bogo Sort does away with the hard work of itterating over an array and offloads the sorting to the checking algorithim by randomising the array until it is sorted. Heres how to use it.

const { BogoSort } = require('@yoloftw/Bad-Sorting');

let arr = [5, 18, 3, 8, 14, 2, 13, 16];

let sorted = BogoSort(arr);

console.log(sorted);
//expected output: [2, 3, 5, 8, 13, 14, 16, 18]

Bogosort boasts a time complexity of O(n * n!), which basically means it could take longer than the life expectancy of the universe to sort a moderately sized list.

Communism Sort

In a communist array everyone is equal. Communism Sort redistributes the wealth to the less fortunate elements resulting in an array that is perfectly equal and therefore sorted.

const { CommunismSort } = require('@yoloftw/Bad-Sorting');

let arr = [1, 6, 4, 10, 13];

let sorted = CommunismSort(arr);

console.log(sorted);
//expected output: [ 6.8, 6.8, 6.8, 6.8, 6.8 ]

Communism Sort achieves a time complexity of O(n), a testament to the efficiency of collective action!

Intelligent Sort

Credit Goes to David Morgan-Mar's Esoteric Algorithims page

From the Intelligent Sort page

The probability of the original input list being in the exact order it's in is 1/(n!). There is such a small likelihood of this that it's clearly absurd to say that this happened by chance, so it must have been consciously put in that order by an intelligent Sorter. Therefore it's safe to assume that it's already optimally Sorted in some way that transcends our naïve mortal understanding of "ascending order". Any attempt to change that order to conform to our own preconceptions would actually make it less sorted.

const { IntelligentSort } = require('@yoloftw/Bad-Sorting');

let arr = [13, 16, 4, 8, 3, 14, 2];

let sorted = IntelligentSort(arr);

console.log(sorted);
//expected output: [13, 16, 4, 8, 3, 14, 2]

Intelligent Sort is one of those elusive constant time algorithims and therefore has the gift of O(1) time complexity.

Miracle Sort

Miracle Sort embraces the power of chance (and cosmic rays) to achieve the impossible. Miracle Sort waits for cosmic rays to flip enough bits in memory for the array to be sorted.

const { MiracleSort } = require('@yoloftw/Bad-Sorting');

let arr = [13, 16, 4, 8, 3, 14, 2];

let sorted = MiracleSort(arr);

console.log(sorted);
//expected output: [2, 3, 4, 8, 13, 14, 16]

Due to Miracle Sort waiting for, well, a miracle the time complexity is a staggering O(∞).

Quantum Bogo Sort

Quantum Bogo Sort assumes that Hugh Everett guy was correct that that there are infact infinite parrallel universes. Quantum Bogo Sort checks if the array is sorted and if not destroys the universe. The only remaining universe is where the array is sorted

const { QuantumBogoSort } = require('@yoloftw/Bad-Sorting');

let arr = [6, 19, 5, 1, 3, 8];

let sorted = QuantumBogoSort(arr);

console.log(sorted);
//expected output: [1, 3, 5, 6, 8, 19]

In the universe where the array was sorted, it was only checked once. Therefore we have another example of a coverted O(1) algorithim

Sleep Sort

Sleep Sort takes a laid-back approach to sorting. Instead of furiously comparing elements it takes a step back and waits for the problem to sort itself.

const { SleepSort } = require('@yoloftw/Bad-Sorting');

let arr = [7, 2, 20, 5, 15, 3];

let sorted = SleepSort(arr);

console.log(sorted);
//expected output: [2, 3, 5, 7, 15, 20]

Sleep Sorts time complexity is a tough one as unlike other algorithims that are dependent on array size, Sleep Sort is dependent on the biggest element. Due to this Sleep Sorts time complexity is O(max(input))

Disclaimer

These sorting systems utilize highly experimental and down right questionable "algorithms". Potential side effects include interdimensional tears, sentient toaster uprisings, and a mild case of the Mondays. Use at your own risk. We're not responsible for any existential crises caused by questioning the nature of sorting after using Bad-Sorting.

Authors