nums function
Generate a List of integers
Implementation
List<int> nums(int a, [int? b, int? step]) {
// if step==null
List<int> numList(int a, [int? b]) {
if (b != null) {
if (b >= a) {
return List.generate(b - a + 1, (index) => index + a);
} else {
return List.generate(a - b + 1, (index) => index + b).reversed.toList();
}
} else {
if (a < 0) {
return List.generate(-a, (index) => -index).reversed.toList();
} else {
return List.generate(a, (index) => index);
}
}
}
if (b == null && step == null) {
return (numList(a));
}
if (b != null && step == null) {
return numList(a, b);
} else {
if (step! <= 0) {
throw ArgumentError('step must be greater than 0');
}
List<int> result = [];
if (b! >= a) {
for (int i = a; i <= b; i += step) {
result.add(i);
}
} else {
for (int i = a; i >= b; i -= step) {
result.add(i);
}
}
return result;
}
}