Skip to content

Instantly share code, notes, and snippets.

@Pchelolo
Forked from 140bytes/LICENSE.txt
Created May 27, 2011 18:15
Show Gist options
  • Save Pchelolo/995812 to your computer and use it in GitHub Desktop.
Save Pchelolo/995812 to your computer and use it in GitHub Desktop.
140byt.es -- Click ↑↑ fork ↑↑ to play!

QuickSort in 138 bytes. Works only on arrays, consists of different elements without zeros.

I`ll be gratefull if someone corrects these bugs.

function(
f //An array to sort
)
{
var l=[], //Sumarray for least elements
r=[], //Subarray for greatest elements
p=f[0], //Element to compare with
a, //Variable to contain array elements
t=arguments.callee, //for recursion
i=n=f.length; //i - loop index, n - just not to rewrite f.length
/*We iterate throw the loop, save elements in variable and
put it to an array for least elements if it is less then p
and to an array for greatest elements, if its greater or equals*/
for(;a=f[--i];a>=p?r.push(a):l.push(a));
/*If array consists of only 1 element - return it,
return a concatenation of sorted least array and
greater array otherwise*/
return n>1?t(l).concat(t(r)):f
}
function(f){var l=[],r=[],p=f[0],a,t=arguments.callee,i=n=f.length;for(;a=f[--i];a>=p?r.push(a):l.push(a));return n>1?t(l).concat(t(r)):f}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment