Skip to content

Instantly share code, notes, and snippets.

@pavelpower
Created October 19, 2013 13:42
Show Gist options
  • Save pavelpower/7055986 to your computer and use it in GitHub Desktop.
Save pavelpower/7055986 to your computer and use it in GitHub Desktop.
used function condition in sort
function _condition(a, b) {
return a - b;
}
Array.prototype.SelectionSort = function(condition) {
var len = this.length, i, min, j,
fn = condition || _condition;
// f() < n^2
for ( i = 0; i < len - 1; i++ ) {
min = i;
for ( j = i + 1; j < len; j++ ) {
if ( fn(this[min], this[j]) > 0 )
min = j;
}
this.swap( i, min );
}
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment