-
Notifications
You must be signed in to change notification settings - Fork 1
randomSubset
Subhajit Sahu edited this page Dec 5, 2022
·
1 revision
Pick an arbitrary subset.
Similar: randomSubset, subsets, isSubset.
function randomSubset(x, n, fr)
// x: a map
// n: number of entries [-1 ⇒ any]
// fr: random number generator ([0, 1))
const map = require('extra-map');
var x = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4]]);
map.randomSubset(x);
// → Map(2) { 'b' => 2, 'c' => 3 }
map.randomSubset(x, 3);
// → Map(3) { 'a' => 1, 'b' => 2, 'd' => 4 }
map.randomSubset(x, 2);
// → Map(2) { 'b' => 2, 'd' => 4 }