mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add .d.ts for weighted (#9687)
This commit is contained in:
parent
eb1ebbda02
commit
2ae9de3df3
30
weighted/weighted-tests.ts
Normal file
30
weighted/weighted-tests.ts
Normal file
@ -0,0 +1,30 @@
|
||||
/// <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));
|
||||
}
|
||||
13
weighted/weighted.d.ts
vendored
Normal file
13
weighted/weighted.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// Type definitions for weighted
|
||||
// Project: https://github.com/Schoonology/weighted
|
||||
// Definitions by: Craig Citro <https://github.com/ccitro>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module 'weighted' {
|
||||
export interface RandomFunc {
|
||||
(): Number;
|
||||
}
|
||||
|
||||
export function select<T> (set: T[], weights: Number[], rand?: RandomFunc): T;
|
||||
export function select<T> (obj: Object, rand?: RandomFunc): T;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user