Hi, we want to be able to randomize all the elements of an array.
The following code adds another prototype
to Array called rand().
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
How it works—first you need to make someArray.rand() a function.
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.