Actions
Feature #12775
closedRandom subset of array
Status:
Rejected
Assignee:
-
Target version:
-
Description
I often see use cases to randomly sample a subset from an array like this:
a = [3, 2, 6, 2, 6, 1]
a.sample(rand(a.length + 1)) # => [2, 6, 6, 3]
I request extending Array#sample
to let it take an option (such as :arbitrary
) for doing that:
a.sample(:arbitrary) # => [2, 6, 6, 3]
or perhaps having an independent method (like samples
) to do it.
a.samples # => [2, 6, 6, 3]
Actions
Like0
Like0Like0Like0Like0Like0Like0