someArray.rand()

Hi, we want to be able to randomize all the elements of an array. The following code adds another prototype to Array called rand().

Back in the day, when I was a new JavaScript programer, I had this JavaScript for Dummies book that I looked into for everything. When I was learning about arrays, I saw the someArray.sort() function along with someArray.join() but I thought I also saw a someArray.rand() function. I was mistaken, there was no such function. Well, today I'm no JavaScript rookie and I created my mistaken function.
How it works—first you need to make someArray.rand() a function.
Array.prototype.rand=addRandFunction
Now whenever you call someArray.rand(), a function by the name of addRandFunction is called instead. When you use the keyword this inside of the function, it contains the entire someArray. When you use return from the fuction, the value is automaticly assigned to someArray. Since someArray is an array, we also want to return an array. All you need to do is construct an array inside of the function and return the arrays name.
This code brought to you by Ultimater from the www.webdeveloper.com message boards.