The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Shuffle An Array

TODO: Pull subtitle into page object

NOTE: This mutates the original array

Shuffle a JavaScript array with:

code_start_default_section code_end_default_section

via: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Shuffle An Array

-- p

NOTE: This mutates the original array

-- p

Shuffle a JavaScript array with:

-- code/
-- javascript

function shuffle(array) {
  let currentIndex = array.length
  let randomIndex

  while (currentIndex != 0) {
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex--
    ;[array[currentIndex], array[randomIndex]] = [
        array[randomIndex], 
        array[currentIndex]
      ]
  }

  return array;
}

// Then
var arr = ['a', 'b', 'c', 'd', 'e', 'f',', 'g'];
shuffle(arr);
console.log(arr);

-- /code

-- p

via: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array


-- categories
-- Miscellaneous

-- metadata
-- date: 2022-01-06 23:04:34
-- id: 23lzhzwb
-- status: scratch
-- type: post
-- SCRUBBED_NEO: false
-- site: aws