Quick sort implementation in JavaScript in prototype style I have implemented quickly the quick sort algorithm in JavaScript using prototype based style.

The code is rather short (http://jsfiddle.net/b8mfY/):

&lt;script&gt;

"use strict";

var Sort = function( inputArray ) {
    this.arrayTest = undefined;
    this.init( inputArray );
};
Sort.prototype.init = function( inputArray ) {
    if ( inputArray instanceof Array &amp;&amp; inputArray.length &gt; 0 ) {
        this.arrayTest = inputArray;
        this.DumpArray( this.arrayTest );
        this.QuickSort( this.arrayTest, 0, this.arrayTest.length - 1 );
        this.DumpArray( this.arrayTest );
    }
    else console.log( 'Input argument isn\'t an array object or its length equals zero.' );
};
Sort.prototype.QuickSort = function( data, first, last ) {
    var i = first;
    var j = last;
    var x = data[ Math.ceil( ( first + last ) / 2 ) ];

    do {
        while ( data[ i ] &lt; x ) i++;
        while ( data[ j ] &gt; x ) j--;

        if ( i &lt;= j ) {
            if ( i &lt; j ) {
                if ( data[ i ] !== data[ j ] ) {
                    var tempItem = data[ i ];
                    data[ i ] = data[ j ];
                    data[ j ] = tempItem;
                }
            }
            i++;
            j--;
        }

    } while ( i &lt;= j );

    if ( i &lt; last ) this.QuickSort( data, i, last );
    if ( first &lt; j ) this.QuickSort( data, first, j );
}
Sort.prototype.DumpArray = function() {
    var output = 'The content of array: [ ';

    if ( this.arrayTest instanceof Array &amp;&amp; this.arrayTest.length &gt; 0 ) {
        this.arrayTest.forEach( function( item ) {
            output = output.concat( [ item, ', ' ].join( '' ) );
        });
    }
    else console.log( 'Can\'t dump the input array. It\'s not an array object or its length equals zero.' );

    output = output.substring( 0, output.length - 2 );
    output = output.concat( ' ].' );
    console.log( output );
};

window.onload = new Sort([
    10,
    1,
    27,
    4090,
    100000,
    2222,
    4934
]);

&lt;/script&gt;


I'm asking for a code review of the quick sort implementation part more than other details.
Looks okay to me.


I would probably go for if ( i != j ) { which could be faster than if ( i &lt; j ) {
You have a ton of short variable names, I guess that's ok for a sorting routine, though I would still rename x to m(iddle).
I would have declared tempItem right under i and j


For the part you are not so interested in;


Capital S in Sort is reserved for constructors
I think reduce is more appropriate than forEach in DumpArray
You should not put code on the same line after an else statement
Now that I think about it the dump routine could be reduced to

Sort.prototype.DumpArray = function() {

var prefix = 'The content of array: [ ';
//Duck typing, just test for join
if( this.arrayTest.join )
    console.log( prefix + this.arrayTest.join(', ') + ' ]'  )
else
    console.log( "Input: " , this.arrayTest );
};