Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript random sort array

// O(n)
function shuffleArray(array) {
    for (let i = array.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [array[i], array[j]] = [array[j], array[i]];
    }
}
Source by css-tricks.com #
 
PREVIOUS NEXT
Tagged: #javascript #random #sort #array
ADD COMMENT
Topic
Name
2+1 =