mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-28 16:45:10 +08:00
31 lines
715 B
TypeScript
31 lines
715 B
TypeScript
/// <reference path="./weighted.d.ts" />
|
|
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));
|
|
}
|