sumTo method
Calculates the sum of all numbers in the range from the current number to other, inclusive.
This method leverages rangeTo to generate the range and then reduces it by summing all elements.
Parameters:
other: The end point of the range to sum to.
Returns:
The sum of all numbers from the current number to other.
Example:
print(1.sumTo(5)); // Outputs: 15 (1+2+3+4+5)
Implementation
num sumTo(num other) => rangeTo(other).reduce((value, element) => value + element);