Skip to content

Instantly share code, notes, and snippets.

@bu1ka
Created November 11, 2015 14:09
Show Gist options
  • Save bu1ka/50ce7fe1fd49c834d126 to your computer and use it in GitHub Desktop.
Save bu1ka/50ce7fe1fd49c834d126 to your computer and use it in GitHub Desktop.
Best sorting algorithm
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