Hi! I was considering how to randomly pick one element from an array. Other langs have that direct method or an easy explicit combination, ie Ruby: array.shuffle.pop
I implemented this little one:
const pickRandom = items => items[Math.trunc(items.length * Math.random())]
Any alternative already here I did not find? Are you interested in a PR?
Hi! I was considering how to randomly pick one element from an array. Other langs have that direct method or an easy explicit combination, ie Ruby:
array.shuffle.popI implemented this little one:
Any alternative already here I did not find? Are you interested in a PR?