function selectionSort(items){

    var len = items.length,
        min, i, j;

    for (i=0; i < len; i++){
    
        // set minimum to this position
        min = i;
        
        // check the rest of the array to see if anything is smaller
        for (j=i+1; j < len; j++){
            if (items[j] < items[min]){
                min = j;
            }
        }
        
        // if the minimum isn't in the position, swap it
        if (i != min){
            swap(items, i, min);
        }
    }
    
    return items;
}
A selection sort implementation in JavaScript. The array
is sorted in-place.
@param {Array} items An array of items to sort.
@return {Array} The sorted array.