lib/selection-sort.js
function sort(array, compare, swap) {
  for (var i = 0; i < array.length - 1; i++) {
    var minIndex = i;

    for (var j = i + 1; j < array.length; j++) {
      if (compare(array, j, minIndex) < 0) {
        minIndex = j;
      }
    }

    if (minIndex !== i) {
      swap(array, i, minIndex);
    }
  }

  return array;
}
function sort(array, compare, swap) {
  for (var i = 0; i < array.length - 1; i++) {
    var minIndex = i;

    for (var j = i + 1; j < array.length; j++) {
      if (compare(array, j, minIndex) < 0) {
        minIndex = j;
      }
    }

    if (minIndex !== i) {
      swap(array, i, minIndex);
    }
  }

  return array;
}
function sort ( array , compare , swap ) { for ( var i = 0 ; i < array . length - 1 ; i ++ ) { var minIndex = i ; for ( var j = i + 1 ; j < array . length ; j ++ ) { if ( compare ( array , j , minIndex ) < 0 ) { minIndex = j ; } } if ( minIndex !== i ) { swap ( array , i , minIndex ) ; } } return array ; }
Sorts an array using selection sort.
@param {Array} array The array to sort.
@param {function} compare The compare function.
@param {function} swap A function to call when the swap operation is
performed. This can be used to listen in on internals of the algorithm.
@returns The sorted array.
Sorts an array using selection sort .