Created
October 19, 2013 13:42
-
-
Save pavelpower/7055986 to your computer and use it in GitHub Desktop.
used function condition in sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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