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.
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 25 МЛН
ТЫ В ДЕТСТВЕ КОГДА ВЫПАЛ ЗУБ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 4,5 МЛН
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 2,9 МЛН
How to Shuffle a JavaScript Array
6:11
OpenJavaScript
Рет қаралды 6 М.
How to shuffle an array (Fisher-Yates algorithm) - Inside code
6:03
How to randomly sort an array? | LeetCode task | JavaScript
10:20
Front-end Science із Сергієм Пузанковим
Рет қаралды 12 М.
Knuth Shuffle made simple in 5 mins
5:29
James Cutajar
Рет қаралды 10 М.
New divisibility rule! (30,000 of them)
26:51
Stand-up Maths
Рет қаралды 276 М.
How to Shuffle An Array in Javascript
6:19
World Class Tech Ed
Рет қаралды 3,1 М.
JavaScript Unit Testing Tutorial for Beginners
48:32
Programming with Mosh
Рет қаралды 81 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 25 МЛН