Created
November 11, 2015 14:09
-
-
Save bu1ka/50ce7fe1fd49c834d126 to your computer and use it in GitHub Desktop.
Best sorting algorithm
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
Array.prototype.sort = function() { | |
'use strict'; | |
var length = this.length; | |
this.forEach(function(el, i) { | |
var min = i + 1; | |
var max = length - min; | |
var newIndex = Math.floor(Math.random() * (max - min + 1)) + min; | |
var _old = this[newIndex]; | |
this[newIndex] = el; | |
this[i] = _old; | |
}, this); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment