User Defined Sort Methods
Sorting Strings
Working example: Deck of Cards

First, create a global object, a deck of cards "A":


A= new Array();
S = ["♥","♦","♣","♠"];
N = [2,3,4,5,6,7,8,9,10,"J","Q","K","A"];

for(var j=0;j<S.length;j++){
for(var i=0;i<N.length;i++){
A[A.length]=S[j]+ " "+N[i];
}
}

 

Then shuffle the deck 300 times, and deal 13 cards.



A.shuffle(300).slice(0,13);
Array.prototype.shuffle= function(times){
var i,j,t,l=this.length;
while(times--){
with(Math){i=floor(random()*l);j=floor(random()*l);}
t=this[i];this[i]=this[j];this[j]=t;
}
return this;
}

More