View Single Post
Old 04-15-2010, 06:05 AM   PM User | #2
mrhoo
Regular Coder

 
Join Date: Mar 2006
Posts: 708
Thanks: 30
Thanked 127 Times in 118 Posts
mrhoo will become famous soon enoughmrhoo will become famous soon enough
There's easier ways to shuffle an array
var myArray = ['Ace',2,3,4,5,6,7,8,9,10,'Jack','Queen','King'];
Code:
Array.prototype.shuffle= function(){
	return this.sort(function(){
		return 0.5 - Math.random();
	})
}
alert(myArray.shuffle())

Code:
Array.prototype.disorder= function(){
	var i, temp, L= this.length, A= this.concat();
	while(--L){
		i= Math.floor(Math.random()*L);
		temp= A[i];
		A[i]= A[L];
		A[L]= temp;
	}
	return A;
}
alert(myArray.disorder());
mrhoo is offline   Reply With Quote
Users who have thanked mrhoo for this post:
001921 (04-15-2010)