0.1.0 • Published 8 years ago
trive v0.1.0
trive
Sequences
To create a sequence use trive.sequence.create(<options>)
.
Options
The options object takes the following properties:
initial
- the initial value (a number) from which to start the sequence. The first item in the sequence will have this value. Default value is1
(is ignored if you pass agovernor
)cycles
- the number of cycles to create (is ignored if you pass agovernor
)increase
- the value by which to increase an item's value. More details: seemode
mode
- the mode to use to calculate the value of items. There are two modes:sequence.modes.Linear
(default) - the linear mode calculates an item's value by adding theincrease
value to the value of the predecessor / governorsequence.modes.Exponential
- calculates an item's value by multiplying its predecessor's / governor's value with theincrease
value
governor
- a sequence used to base values on. If you pass a governor the sequence will have- the same number of cycles as the governor (i.e. the
cycles
value is ignored) have its item values based on the item values of the governor (instead of using an item's predecessor as the base value)
- the same number of cycles as the governor (i.e. the
Result
The result of sequence.create
is an object of the following structure:
{
items:[
{ value: 1 },
...
{ value: n }
]
}
Examples
Linear Sequence without Governor
const sequence = require('trive').sequence
let options = {
cycles: 3,
initial: 10,
increase: 5,
mode: sequence.modes.Linear
}
let s = sequence.create(options)
The resulting sequence s
looks like this:
{
items: [
{ value: 10 },
{ value: 15 },
{ value: 20 }
]
}
Exponential Sequence without Governor
let options = {
initial:10,
cycles:3,
increase:1.5,
mode:sequence.modes.Exponential
}
let s = sequence.create(options)
The resulting sequence s
looks like this:
{
items: [
{ value: 10 },
{ value: 15 },
{ value: 22.5 }
]
}
Sequnece with Governor
0.1.0
8 years ago