For example, we have the following array:
let arr = [1, 2, 3, 4, 5] => [3, 5, 4, 1, 2] // a possible shuffle result
Shuffling an array of values is considered one of the oldest problems in computer science. Shuffling is possible with the Fisher-Yates shuffle algorithm for generating a random permutation of a finite sequence. That is to say, the algorithm shuffles the sequence.
Richard Durstenfeld introduces the modern version of the Fisher-Yates shuffle designed for computer use.
In case of coding with ES6/ECMAScript 2015, which allows assigning two variables immediately, the code will be shorter: