Sorting array using Javascript function - Understanding
问题 I decided to get shuffled values from array. for that i used this function, i got it from net, it works fine. But i don't know, how it's works... any one can help me to understand this? my code is : function rand(ar){ return 0.5-Math.random(); } var ar = [5,10,15,20,25] ar.sort(rand); console.log(ar) I am using this function for getting new shuffled array values from the declared one. 回答1: This code is using the supplied rand function as the comparison operator for the Array.Sort method (http