Simple Position Chooser
This package allows for an easy and simple way to choose multiple positions using a string or an array with the desired rules.
How to use
The way to choose the desired positions is by using any of the rules seperated by a comma in a string or by having the rules in an array. Then you use the generated function with the start position and end position to generate the derised positions.
(X and Y represent an non negative integer number)
* : adds all positions. This is a special rule because it cannot be used with any other rule.
X : adds the position X.
X-Y : adds all positions between X and Y (X and Y included).
-X : adds all positions between 0 and X (same as 0-X)
X- : adds all positions between X and the last positions (X included)
/X : adds all positions that are multiple of X
even -> adds all even positions
odd -> adds all odd positions
- Any invalid rule will simply be ignored.
- Any position will only be added once, even if there are more than one rule defining it.
- 0 is a univerval multiple
- The list of desired positions is always ordered.
Example: '1,3,7-9' will adds positions 1,3,7,8 and 9.
How to use
var processPositionsString = processPositionsString;//The rule list can be a string or an arrayvar processor=;//orvar processor=;// Note: The end value is excluded//processor(start,end)//generates [ 0, 1, 4, 5, 8, 12, 13, 14, 15, 16, 17, 20, 24, 28 ]//generates [ 15, 16, 17, 20, 24, 28, 32, 36 ]
// In this examplevar arrayvar processPositionsString = processPositionsString;//The rule returns all possitions from 0 to 10 and all multiples of 5var processor=;//goes trough all the array positions that are between 0 and 10 or are multiple of 5