I have recently been learning about creating one's own sort functionality and the various sort algorithms. I wanted to create my own QuickSort algorithm, as it seemed a good balance between ease of implementation and processing efficiency.

The below code does work. I was wondering if there would be anyone willing to evaluate these functions and tell me whether this implementation truly takes advantage of the QuickSort algorithm's potential for efficiency. (As it would be perfectly possible to create an implementation that operated on the basic concept but in an inefficient way, like creating new sub-arrays.)

Code:
//swap values in the array at two specified indicies
function swap(arr, ind1, ind2)
{
	var tmp = arr[ind1];
	arr[ind1] = arr[ind2];
	arr[ind2] = tmp;
}
//with a given range and pivot index, create the partition, with lesser values to the left and greater to the right
function partition(arr, left, right, pIndex)
{
	var pValue = arr[pIndex];
	
	//move the pivot item to the end
	swap(arr, pIndex, right);
	
	//starting with the first item, loop through all but the pivot item
	var storeIndex = left;
	for (var i=storeIndex; i<right; i++)
	{
		//if a value is found less than or equal to the pivot, 
		//swap with the temporary index and increase the temporary index
		if (arr[i] <= pValue)
		{
			swap(arr, i, storeIndex);
			storeIndex++;
		}
	}
	//swap the pivot item back to the temporary index, as this is now the point between less and greater values
	swap(arr, storeIndex, right);
	
	return storeIndex;
}
//the QuickSort function
function quickSort(arr, left, right)
{
	//sort the entire array if no range is given
	if (typeof(left)=='undefined') left = 0;
	if (typeof(right)=='undefined') right = arr.length - 1;
	
	//no need to do anything if there's no valid range
	if (right > left)
	{
		//get the pivot index and do the partition
		var pIndex = left;
		var newPIndex = partition(arr, left, right, pIndex);
		
		//now recurse on the ranges to the left and right of the new pivot index
		quickSort(arr, left, (newPIndex - 1));
		quickSort(arr, (newPIndex + 1), right);
	}
}

var numbers = [3, 7, 8, 5, 2, 1, 9, 5, 4];

alert(numbers.join(','));

quickSort(numbers);

alert(numbers.join(','));