Shuffle an Array - Fisher-Yates shuffle algorithm -JavaScript Cardio |

Опубликовано: 16 Октябрь 2024
на канале: UniSwann
213
17

Coding challenge - Shuffle an Array of elements.

The Fisher-Yates algorithm is named after Ronald Fisher and Frank Yates.
It’s an algorithm used to shuffle a sequence of finite items, like an array for instance.
The algorithm works by swapping a random element from your array with the last element in that array repeatedly.
These are the steps taken by the algorithm to shuffle an array:
Pick a random index number between the first and the last index position in your array
Swap the element at the random index with the last index element
Repeat step one, but leave the last index out of the random selection
Stop the shuffle when only the starting index is left in the random selection