Course of Raku / Functional, concurrent, reactive, and web programming / Functional programming / Reduction / Exercises / Product of a list

Solution: Product of a list

Here is a possible solution to the task.

Code

say [*] 1..6;

🦋 You can find the source code in the file product-list.raku.

Output

720

Comments

  1. [*] inserts * between every element of the range, multiplying them all.

  2. 1 * 2 * 3 * 4 * 5 * 6 is 720 — the same as the factorial of 6.

Course navigation

Product of a list   |   Join the strings