aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/barroff/raku/ch-1.p6
blob: 2668667bdc4e73fece068f6eee895754b578395a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env raku

use v6.d;

sub last-word(Str $str --> Int) {
    ($str.words)[* - 1].chars;
}

#| Run test cases
multi sub MAIN('test') {
    use Test;
    plan 3;

    is last-word("The Weekly Challenge"), 9, 'works for "The Weekly Challenge"';
    is last-word("   Hello   World    "), 5, 'works for "   Hello   World    "';
    is last-word("Let's begin the fun"), 3, 'works for "Let\'s begin the fun"';
}

#| Take user provided number like "Perl Weekly Challenge" l a
multi sub MAIN(*@words) {
    say last-word(@words.join(' '));
}