1.1.1 • Published 7 years ago

get-random-from-array v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

getRandomFromArray

This gets a random value from an array, but never gets the same value twice in a row.

const makeGetRandomFromArray = require('get-random-from-array')

const arrayOfKittensImages = [
  {
    src: 'https://pbs.twimg.com/profile_images/562466745340817408/_nIu8KHX.jpeg,'
    href: 'https://twitter.com/emrgencykittens'
  },
  ...
]

// The `makeGetRandomFromArray` will return
// a closure function i.e. `_getRandomFromArray`
const getRandomKitten = makeGetRandomFromArray(arrayOfKittensImages)

// Then each time you call the closure you will get a new random value
console.log(getRandomKitten())
/*
{
  src: 'random-kitten-src.jpg',
  href: 'https://random-kitten-href.com'
}
*/
1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago