Skip to content

Random pick #12

Description

@dgilperez

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions