Quick actions

cmd+k|ctrl+k

Navigation

Languages

Reverse Word

Snippet info

Language

Raku

Visibility

public

Author

fernando-correa

Created

2024-07-28T17:43:28.336738Z

Updated

2024-07-28T17:43:28.336738Z

use Test;

sub reverse-word(Str() $str, Str $char where *.chars == 1) {
    do if $str.index: $char -> Int $i {
        $str.comb.head($i + 1).sort.join ~ $str.substr: $i + 1
    } else {
        $str
    }
}

is my $r1 = "challenge".&reverse-word("e"), "acehllnge", $r1;
is my $r2 = "programming".&reverse-word("a"), "agoprrmming", $r2;
is my $r3 = "champion".&reverse-word("b"), "champion", $r3;
INFO