Course of Raku / Advanced / Subroutines / Signatures / Exercises / Sum all arguments
Solution: Sum all arguments
Here is a possible solution to the task.
Code
sub total(*@nums) {
[+] @nums
}
say total(3, 5, 7);🦋 You can find the source code in the file sum-all-arguments.raku.
Output
15Comments
The slurpy parameter
*@numscollects all the arguments into the array@nums, however many there are.The reduction meta-operator
[+]then adds them all together, giving15.