Javascript Array qsort()

Description

Javascript Array qsort()

Array.prototype.qsort = function()
{
    if (this.length < 2)
        return this;

    var head = this.shift();

    return unpack(function(low, high) {
        return [].concat(low.qsort(), head, high.qsort());
    }, this.partition(function(_) { return _ < head; }));
};

console.log([ 5, 4, 3, 2, 1].qsort());//from  ww  w.j  a v  a  2 s. c  o  m



PreviousNext

Related