Added counter to lists

This commit is contained in:
2023-12-19 22:41:30 +02:00
parent e557e5565b
commit facb30be3a
3 changed files with 48 additions and 0 deletions

View File

@ -977,6 +977,7 @@ export class UserAPI {
return this.counters[name].value;
};
$ = this.counter;
count = this.counter;
// =============================================================
// Iterator functions (for loops, with evaluation count, etc...)
@ -1737,12 +1738,21 @@ export class UserAPI {
* @param step - The step value of the array
* @returns An array of values between start and end, with a given step
*/
function countPlaces(num: number) {
var text = num.toString();
var index = text.indexOf(".");
return index == -1 ? 0 : (text.length - index - 1);
}
const result: number[] = [];
if ((end > start && step > 0) || (end < start && step < 0)) {
for (let value = start; value <= end; value += step) {
result.push(value);
}
} else if((end > start && step < 0) || (end < start && step > 0)) {
for (let value = start; value >= end; value -= step) {
result.push(parseFloat(value.toFixed(countPlaces(step))));
}
} else {
console.error("Invalid range or step provided.");
}