How to SHUFFLE AN ARRAY in 4 minutes! 🔀

preview_player
Показать описание
"The Fisher–Yates shuffle is an algorithm for shuffling a finite sequence. The algorithm takes a list of all the elements of the sequence, and continually determines the next element in the shuffled sequence by randomly drawing an element from the list until no elements remain. The algorithm produces an unbiased permutation: every permutation is equally likely. The modern version of the algorithm takes time proportional to the number of items being shuffled and shuffles them in place."

- Eberl, Manuel (2016). "Fisher–Yates shuffle". Archive of Formal Proofs. Retrieved 28 September 2023.
Рекомендации по теме
Комментарии
Автор

// Fisher-Yates algorithm

const cards = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K'];

shuffle(cards);

console.log(cards);

function shuffle(array){
for(let i = array.length - 1; i > 0; i--){
const random = Math.floor(Math.random() * (i + 1));

[array[i], array[random]] = [array[random], array[i]];
}
}

BroCodez
Автор

Day 3 ends…. I’ll go check more about reduce()

Gigglesaintlame
Автор

oh my god bro this is so helpful! thanks for saving me 25 lines of spaghetti code!

himynameisidiot
Автор

Could you create a tutorial about Rust programming language?

B
Автор

Just a random comment to shuffle the YouTube algorithm🎉

jubba
Автор

bro i am following your previous js playlist should i continue that or should i continue from this series

educationalbro
Автор

bro please elaborate a lil bit more of JS topics...

dmowzlw
Автор

What a stupid language. But explanation is good.

tomiczdarko