Skip to content

Instantly share code, notes, and snippets.

@g-a-v-i-n
Created June 21, 2018 01:39
Show Gist options
  • Save g-a-v-i-n/5863acd03e35e3c963c1e16b89ba81eb to your computer and use it in GitHub Desktop.
Save g-a-v-i-n/5863acd03e35e3c963c1e16b89ba81eb to your computer and use it in GitHub Desktop.
const orginal = [
  [a, b, c, d],
  [e, f, g, h],
  [i, j, k, l, e, h, j, i],
  [m, n, o, p],
]

const randomItems = orginal.map((subArray) => {
  return mapFunc(subArray))
}


/// DEFINITIONS

const mapFunc = (subArray) => {
  const randomIndex = randInt(subArray.length - 1)
  const randomSelection = subArray[randomIndex]
  return randomSelection
}

const randInt = (maximumNumber) => {
  return Math.floor(Math.random() * maximumNumber)
}






// NOTES

0 - 1

0.25

>> [b,
    h,
    i,
    p]



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment