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

The longest string

Problem

Using the reduce method with a block, find and print the longest string in the list 'cat', 'elephant', 'dog', 'fox' — the one with the most characters. A metaoperator will not help here: the block has to compare the two candidates itself.

Example

The program prints:

elephant

Solution

See the solution

Course navigation

Solution: Join the strings   |   Solution: The longest string