Given an array, how can I extract n
non overlapping random samples of size m
from it?
For example, given the array:
const arr = [1, 2, 3, 4, 5, 6, 7, 8];
calling sample(arr, 3, 2)
would for example return [[7, 8], [4, 5], [2, 3]]
, calling sample(arr, 2, 4)
would necessarily return [[1, 2, 3, 4], [5, 6, 7, 8]
, and calling sample(arr, 5, 2)
would throw an error.
Aucun commentaire:
Enregistrer un commentaire