Skip to content

randomSubset

Subhajit Sahu edited this page Dec 22, 2022 · 1 revision

Pick an arbitrary subset.

Similar: randomSubset, subsets, hasSubset.


function randomSubset(x, n, fr)
// x:  entries
// n:  number of entries [-1 ⇒ any]
// fr: random number generator ([0, 1))
const entries = require('extra-entries');

var x = [["a", 1], ["b", 2], ["c", 3], ["d", 4]];
[...entries.randomSubset(x)];
// → [ [ "a", 1 ], [ "d", 4 ] ]

[...entries.randomSubset(x, 3)];
// → [ [ "a", 1 ], [ "b", 2 ], [ "d", 4 ] ]

[...entries.randomSubset(x, 2)];
// → [ [ "b", 2 ], [ "d", 4 ] ]


References

Clone this wiki locally