List of utility methods to do Array Exchange
exchange(i1,i2)Array.prototype.exchange = function(i1,i2) { var tmp = this[i1]; this[i1] = this[i2]; this[i2] = tmp; }; var randomizeInPlace = function(A) { for (var i = 1, n = A.length; i < n; i++){ A.exchange(i,getRandomIntInclusive(0,i)); return A; }; module.exports = randomizeInPlace; | |
exchange(i1,i2)Array.prototype.exchange = function(i1,i2) { var tmp = this[i1]; this[i1] = this[i2]; this[i2] = tmp; }; |