jondashkyle / nanopage

super handy utilities for traversing flat content state
Apache License 2.0
42 stars 4 forks source link

shuffle #10

Closed s3ththompson closed 6 years ago

s3ththompson commented 6 years ago

Might be nice to have .shuffle() alongside .sort(). I've implemented it manually with:

function shuffle (array) {
  var i = 0
    , j = 0
    , temp = null

  for (i = array.length - 1; i > 0; i -= 1) {
    j = Math.floor(Math.random() * (i + 1))
    temp = array[i]
    array[i] = array[j]
    array[j] = temp
  }
}
jondashkyle commented 6 years ago

super down for this!

jondashkyle commented 6 years ago

added here: https://github.com/jondashkyle/nanopage/commit/6526c150c623b4786fa3cb9202de3b6fe50938ac