JSFiddle - React, Tailwind, and code Playground
by wookiehangover
JavaScript
Array.prototype.quicksort = quicksort = function( arr ) {
var pivot,
_left = [],
_right = [],
obj = arr || this,
end = obj.length;
if( end <= 1 ) {
return obj;
}
pivot = Math.floor( end / 2 );
while( end -- ) {
if ( obj[end] < obj[pivot] && end !== pivot) {
_left.push(obj[end]);
} else {
_right.push(obj[end]);
}
}
return _left.quicksort().concat(_right.quicksort());
}
var a = [], x = 1000;
while(x--) {
a.push(x);
}
console.time('quicksort');
console.debug(a.quicksort());
console.timeEnd('quicksort');