Timeline for How can I shuffle an array?
Current License: CC BY-SA 3.0
38 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 10, 2021 at 7:14 | comment | added | dcts | be aware this changes the initial array, its not a functional approach. Just leaving this here for anyone that is blindely copying this (as I did lol). | |
| Jul 26, 2020 at 22:16 | comment | added | Epic Speedy |
Would be better if some of the lets were replaced with const as they aren't modified at all, except for counter.
|
|
| Sep 28, 2017 at 11:16 | review | Suggested edits | |||
| Sep 28, 2017 at 12:21 | |||||
| Feb 25, 2016 at 17:01 | history | rollback | Flexo - Save the data dump♦ |
Rollback to Revision 17
|
|
| S Feb 22, 2016 at 11:48 | history | suggested | JoniS | CC BY-SA 3.0 |
corrected to be 100% accurate
|
| Feb 22, 2016 at 11:09 | review | Suggested edits | |||
| S Feb 22, 2016 at 11:48 | |||||
| S Feb 22, 2016 at 10:57 | history | suggested | JoniS | CC BY-SA 3.0 |
Added Addy Osmani's enhancement of the Fisher-Yates shuffle orginaly mentioned
|
| Feb 22, 2016 at 10:03 | review | Suggested edits | |||
| S Feb 22, 2016 at 10:57 | |||||
| Jan 26, 2016 at 16:21 | history | edited | akohout | CC BY-SA 3.0 |
Use ES6's let for variable definitions
|
| Oct 29, 2014 at 16:49 | comment | added | JonnyRaa | really interesting post by jeff atwood about this algorithm. blog.codinghorror.com/the-danger-of-naivete I wanted to know why it is implemented the way it is | |
| Aug 21, 2014 at 16:36 | comment | added | Blender | @Volter9: Because the distribution isn't going to be uniform. | |
| Aug 21, 2014 at 16:11 | comment | added | volter9 | Why you just don't use random + Array.prototype.sort? It's easier and less code than both answers. | |
| Jan 8, 2014 at 17:15 | history | undeleted | Blender | ||
| Jan 8, 2014 at 17:15 | history | edited | Blender | CC BY-SA 3.0 |
deleted 788 characters in body
|
| Jan 8, 2014 at 17:02 | history | deleted | Blender | via Vote | |
| Jan 8, 2014 at 14:04 | comment | added | Richard | there is still a bug in this answer! try: shuffle([1,2,3]); the value "1" is never on position 0 in the returned array | |
| Oct 11, 2013 at 23:50 | comment | added | Blender |
@rvighne: I tested both and | 0 was marginally faster.
|
|
| Oct 11, 2013 at 22:51 | comment | added | rvighne |
The ~~ is even better than | 0: index = ~~(Math.random() * counter)
|
|
| Sep 28, 2013 at 1:12 | comment | added | Blender | @ThomasWood: Yep, you're right. alltom's suggestion wasn't correct. | |
| Sep 28, 2013 at 1:10 | history | rollback | Blender |
Rollback to Revision 13
|
|
| Sep 28, 2013 at 0:25 | comment | added | Thomas Wood |
That first answer seems to have a bug. About once in every 15 runs I get an extra undefined column. jsfiddle.net/tomasswood/z8zm7
|
|
| Sep 2, 2013 at 19:13 | history | edited | Blender | CC BY-SA 3.0 |
added 12 characters in body
|
| Jul 29, 2013 at 14:05 | history | edited | Dan | CC BY-SA 3.0 |
deleted 4 characters in body
|
| Jun 27, 2013 at 0:28 | comment | added | Blender |
@BrianMortenson: Pass it through and look at the resulting code. It replaces the while loop with a for loop and turns counter > 0 into 0 < counter. I'm not entirely sure what parts speed it up, but the end result is a tiny bit faster than the original.
|
|
| Jun 27, 2013 at 0:25 | comment | added | undefined | Care to elaborate on what Closure Compiler does to speed this up? | |
| Jun 9, 2013 at 16:28 | history | edited | Blender | CC BY-SA 3.0 |
deleted 75 characters in body
|
| Jun 9, 2013 at 16:22 | history | edited | Blender | CC BY-SA 3.0 |
edited body; Post Made Community Wiki
|
| Jun 8, 2013 at 20:36 | history | edited | Blender | CC BY-SA 3.0 |
added 1 characters in body
|
| May 28, 2013 at 19:59 | history | edited | Blender | CC BY-SA 3.0 |
added 71 characters in body
|
| May 22, 2013 at 7:05 | history | edited | Blender | CC BY-SA 3.0 |
added 60 characters in body
|
| May 22, 2013 at 6:41 | review | Suggested edits | |||
| May 22, 2013 at 6:41 | |||||
| May 13, 2013 at 16:33 | history | edited | Blender | CC BY-SA 3.0 |
added 48 characters in body
|
| May 13, 2013 at 16:26 | history | edited | Blender | CC BY-SA 3.0 |
added 475 characters in body
|
| May 13, 2013 at 16:17 | history | edited | Blender | CC BY-SA 3.0 |
added 2 characters in body
|
| May 13, 2013 at 16:11 | history | edited | Blender | CC BY-SA 3.0 |
deleted 15 characters in body
|
| May 4, 2013 at 19:16 | history | edited | Blender | CC BY-SA 3.0 |
added 134 characters in body
|
| May 4, 2013 at 19:04 | history | edited | Blender | CC BY-SA 3.0 |
added 264 characters in body
|
| Jun 8, 2011 at 5:01 | history | answered | Blender | CC BY-SA 3.0 |