The optimal solution to shuffle an Array in JavaScript (pitayan.com) 5 points by daiyanze 5y ago ↗ HN
[–] flywheel 5y ago ↗ Surprised Array.sort wasn't mentioned.[1,2,3,4,5,6,7,8,9,0].sort(()=>Math.random()*2-1) [–] daiyanze 5y ago ↗ Nice one there!sort is an elegant solution even tho the time complexity may be O(nlogn).
[–] daiyanze 5y ago ↗ Nice one there!sort is an elegant solution even tho the time complexity may be O(nlogn).
2 comments
[ 3.2 ms ] story [ 12.6 ms ] thread[1,2,3,4,5,6,7,8,9,0].sort(()=>Math.random()*2-1)
sort is an elegant solution even tho the time complexity may be O(nlogn).