Template Deduction Guide
Template Deduction Guide
March 15, 2022
How to select a specific node that contains a specific value?
How to select a specific node that contains a specific value?
March 29, 2022

March 22, 2022

How to shuffle an array in JavaScript?

Fisher-Yates (Knuth) shuffle is one of the algorithms that can be used to shuffle an array with O(n) complexity.

function shuffle (array) { 
     let randomIndex;
for (let currentIndex = array.length currentIndex >= 0; --currentIndex) {
1;
      randomIndex = Math.floor(Math.random()
currentIndex);
      [array[currentIndex], array[randomIndex]] = [ array[randomIndex],

        array[currentIndex],
      ];
    }
  return array;

}
How to shuffle an array in JavaScript?
This website uses cookies to improve your experience. By using this website you agree to our Data Privacy Statement
Read more