Class: Ratio

lib/ratio~ Ratio

Class sampling keys based on ratio.


new Ratio(weights)

Create a ratio.

Parameters:
Name Type Description
weights Object.<string, integer>

Map representing pairs of key and weight.

Source:
Example
new Ratio({key1: 1, key2: 2}); // => Ratio's instance

Methods


sample()

Sample a key based on ratio.

Source:
Returns:
Type
string | null
Example
new Ratio({key1: 1, key2: 2}).sample(); // => "key1" with a third, or "key2" with two third