mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Change to natural counting in range[N] operator (#3609)
* Add range operator and documentation * Use 1-based counting in range[N], update docs
This commit is contained in:
parent
0f3912ba95
commit
b9df224f99
@ -34,8 +34,16 @@ exports.range = function(source,operator,options) {
|
|||||||
}
|
}
|
||||||
switch(parts.length) {
|
switch(parts.length) {
|
||||||
case 1:
|
case 1:
|
||||||
beg = 0;
|
|
||||||
end = parts[0];
|
end = parts[0];
|
||||||
|
if (end >= 1) {
|
||||||
|
beg = 1;
|
||||||
|
}
|
||||||
|
else if (end <= -1) {
|
||||||
|
beg = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
inc = 1;
|
inc = 1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -18,28 +18,31 @@ op-output: a series of evenly spaced numbers ranging from `<begin>` to `<end>`
|
|||||||
<$list variable=n filter="[range[$range$]]"><<n>> </$list>
|
<$list variable=n filter="[range[$range$]]"><<n>> </$list>
|
||||||
\end
|
\end
|
||||||
|
|
||||||
The `range` operator allows a range of numbers to be enumerated, similar to a `for` loop in other programming languages. It's useful in combination with the [[Formula Plugin]].
|
The `range` operator produces a list of numbers counting up or down. It's useful for counting and numbering, or in combination with the [[Formula Plugin]].
|
||||||
|
|
||||||
|!Purpose|produce a range of numbers|
|
|!Purpose|produce a range of numbers|
|
||||||
|!Input|ignored.|
|
|!Input|ignored.|
|
||||||
|!Parameter|1-3 numbers separated by `,` or `;`.|
|
|!Parameter|1-3 numbers separated by `,` or `;`.|
|
||||||
|!Output|A range of numbers starting with |
|
|!Output|A series of evenly spaced numbers ranging from `<begin>` to `<end>`|
|
||||||
|!`!` Output|As ''Output'', but with order reversed.|
|
|!`!` Output|As ''Output'', but with order reversed.|
|
||||||
|
|
||||||
The parameter has three forms:
|
The parameter has three forms:
|
||||||
|
|
||||||
* `<end>`
|
|Parameter|Output|h
|
||||||
* `<begin>,<end>`
|
|`<end>`|Whole numbers up to `<end>`.|
|
||||||
* `<begin>,<end>,<step>`
|
|`<begin>,<end>`|Numbers from `<begin>` to `<end>`, spaced by whole numbers.|
|
||||||
|
|`<begin>,<end>,<step>`|Numbers from `<begin>` to `<end>` spaced out by `<step>`.|
|
||||||
|
|
||||||
Each part must be a number, and works as follows:
|
Each part must be a number, and works as follows:
|
||||||
|
|
||||||
* `<begin>`: start counting at this number. Defaults to 0.
|
* `<begin>`: start counting at this number.
|
||||||
|
** Defaults to 1 if `<end>` is at least 1 (or -1 if `<end>` is at most -1).
|
||||||
* `<end>`: stop counting at this number.
|
* `<end>`: stop counting at this number.
|
||||||
** It will be included unless it falls between two steps.
|
** This number will appear in the list unless it falls between two steps.
|
||||||
* `<step>`: count up (or down) by this amount.
|
* `<step>`: count up (or down) by this amount.
|
||||||
** It may be negated so it counts in the right direction.
|
** Defaults to 1.
|
||||||
** It cannot be zero.
|
** Cannot be zero.
|
||||||
|
** We always count from `<begin>` toward `<end>`, whether `<step>` is positive or negative.
|
||||||
|
|
||||||
The number of decimal points in the output is fixed, and based on the parameter with the //most// decimal points.
|
The number of decimal points in the output is fixed, and based on the parameter with the //most// decimal points.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user