mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
13 lines
408 B
JavaScript
13 lines
408 B
JavaScript
|
var quicksort = function () {
|
||
|
var sort = function(items) {
|
||
|
if (items.length <= 1) return items;
|
||
|
var pivot = items.shift(), current, left = [], right = [];
|
||
|
while(items.length > 0) {
|
||
|
current = items.shift();
|
||
|
current < pivot ? left.push(current) : right.push(current);
|
||
|
}
|
||
|
return sort(left).concat(pivot).concat(sort(right));
|
||
|
};
|
||
|
|
||
|
return sort(Array.apply(this, arguments));
|
||
|
};
|