Topic awaiting preservation: Challenge your JavaScript skills (Page 1 of 1) |
|
---|---|
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 10-21-2005 06:19
This is an attempt to spark some conversation or creativity. |
Bipolar (III) Inmate From: |
posted 10-21-2005 12:39
Am out of energy for the implementation, but I suspect the first trick is actually determining... what is "order" in that array. |
Paranoid (IV) Inmate From: France |
posted 10-21-2005 16:02
liorean and I proposed some implementations in An elegant way to mix arrays arrays... |
Maniac (V) Mad Scientist From: :morF |
posted 10-22-2005 06:10
Well, randomising the elements, in its most simple form, would involve a random number generator limited ot the number of elements in your array, and a secondary storage array. The random number generator detemines which index will be read out, then subsequently determines which index its data will go into in the new array. Keep repeating until the counter tells you you've got all of your elements out, and, voila, done. You'd put used indexes into a tokenised list or something, and have a check within your loop to make sure you're not repeating values. |
Bipolar (III) Inmate From: |
posted 10-22-2005 11:54
Ok, let me see if... well, this, at first, sounded like a challenge: quote:
|
Paranoid (IV) Inmate From: France |
posted 10-22-2005 12:29
I don't claim the implementation I posted before are good. Btw you can see in that same thread that sometime I trigger a hammer to smash little flies My Array.prototype.shuffle method works only for straight arrays ( with no textual keys ). I should add a pass before to build a little list of keys before really shuffling the items. |
Bipolar (III) Inmate From: |
posted 10-22-2005 13:22
poi, while we're at it, and while I am performing my monthly comp maintenance, would you mind spending some time on Q? |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 10-22-2005 22:32 |
Paranoid (IV) Inmate From: France |
posted 10-23-2005 04:44 |
Maniac (V) Mad Scientist From: :morF |
posted 10-23-2005 14:33
I certainly shall implement it, just as soon as I learn to write Javascript. I could do it for you in PHP, C and possibly Visual Basic... but, lets have a burl and see what we get... |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 10-24-2005 18:36
Hm.. I may be cheating using a built in array function but here we go: |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 10-24-2005 20:51
That's an interesting approach, bit. I wonder if it provides an equal chance of all random configurations? |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 10-24-2005 21:54
heh after looking at poi's post I'm reinventing the wheel (my other solution was liorien's) |
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 10-24-2005 22:05
I guess it didn't really work to ask a question that had already been answered on this forum =) |
Paranoid (IV) Inmate From: France |
posted 10-24-2005 23:04
For the record, I understood : "If you find this problem simple, wait until others have had a try before posting your answer." as : "Don't let the apparent simplicity fool you. It can be much more complex than it seems ... and Slime uncovered some nifty subtleties in the other thread." |