Custom sort : shuffle an array the quick way
Sat Jun 19 2021 07:10:34 GMT+0000 (Coordinated Universal Time)
Saved by @hisam #javascript #vanilla #sort #randomize #array
As the function we pass to .sort() is looking for either a positive or negative number to either move the item ‘up’ or ‘down’ in the array, each item has a chance of being moved in either direction giving us a shuffled array of items. This works for a rough-and-ready approach but might not give you a truly random shuffle.
Comments