mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
30 lines
672 B
TypeScript
30 lines
672 B
TypeScript
import * as weighted from 'weighted';
|
|
|
|
function testSet() {
|
|
var options = ['Wake Up', 'Snooze Alarm'];
|
|
var weights = [0.25, 0.75];
|
|
|
|
console.log('Decision:', weighted.select(options, weights));
|
|
}
|
|
|
|
function testObj() {
|
|
var options = {
|
|
'Wake Up': 0.25,
|
|
'Snooze Alarm': 0.75
|
|
};
|
|
|
|
console.log('Decision:', weighted.select(options));
|
|
}
|
|
|
|
function testOverrideRand() {
|
|
var options = ['Wake Up', 'Snooze Alarm'];
|
|
var weights = [0.25, 0.75];
|
|
|
|
function rand() {
|
|
return 4; // chosen by fair dice roll.
|
|
// guaranteed to be random.
|
|
}
|
|
|
|
console.log('Decision:', weighted.select(options, weights, rand));
|
|
}
|