JavaScript: Shuffle Array Items using Fisher Yates Method

  Рет қаралды 2,524

Crypters Infotech

Crypters Infotech

Күн бұрын

Пікірлер: 5
@Covyessien
@Covyessien 2 ай бұрын
Thanks a lot ma! I totally get you!❤
@techies110
@techies110 4 жыл бұрын
logic of ----------> Math.random()*(i+1)); ------------> can you please explain why you multiplied *(i+1)
@constantinmunteanu3519
@constantinmunteanu3519 3 жыл бұрын
Math.random() generates a number between 0 and 0.999 not including 1. Remember that any random generated number * number of last index in array starting with 0 will equal a number that is less than the last index in the array. For example const nums = [10, 20, 30, 40, 50, 60]. Last index is 5. If math.Random() is 0.999 then 0.999 * 5 = 4 after Math.floor() , 4 being the randomIndex. On the first loop, 60 will get swapped with 50 in this case. You could write just ()* i without the + 1, but without the +1, the last value of an array will never have a chance to stay the same, 60 to just stay 60 like it could here (0.999 * (5 + 1)) where a randomIndex will be 5 and last index is also 5. Both * i and (i + 1) are ok in most cases.
@whoami5583
@whoami5583 4 жыл бұрын
Mam i can't understand. Can you taught this in hindi
@CryptersInfotech
@CryptersInfotech 4 жыл бұрын
Sorry, not practical.
How to randomly sort an array? | LeetCode task | JavaScript
10:20
Front-end Science із Сергієм Пузанковим
Рет қаралды 12 М.
How to shuffle an array (Fisher-Yates algorithm) - Inside code
6:03
Каха и лужа  #непосредственнокаха
00:15
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
sort Array Method | JavaScript Tutorial
5:47
Florin Pop
Рет қаралды 142 М.
Knuth Shuffle made simple in 5 mins
5:29
James Cutajar
Рет қаралды 10 М.
W3School java Script Array Sorting part1
22:15
Simple Coding
Рет қаралды 119
How to SHUFFLE AN ARRAY in 4 minutes! 🔀
4:05
Bro Code
Рет қаралды 13 М.
Каха и лужа  #непосредственнокаха
00:15