use Test;
multi sort-letters(:@letters!, :@indexes!) {
(@indexes Z=> @@letters).sort>>.value.join
}
multi sort-letters(Str :$letters!, :@indexes!) {
sort-letters :letters($letters.comb), :@indexes
}
multi sort-letters($letters, +@indexes) {
sort-letters :$letters, :@indexes
}
for [
\(
:letters< R E P L >,
:indexes[3, 2, 1, 4],
), "PERL",
\(
:letters<A U R K>,
:indexes[2, 4, 1, 3],
),
"RAKU",
\(
:letters<O H Y N P T>,
:indexes(5, 4, 2, 6, 1, 3),
),
"PYTHON",
] -> Capture \c (:@letters, :@indexes), Str $answer {
is sort-letters(|c), $answer, c;
my \c2 = \(:letters(@letters.join), :@indexes);
is sort-letters(|c2), $answer, c2;
is @letters.&sort-letters(@indexes), $answer, "positional: { c.gist }";
is @letters.join.&sort-letters(|@indexes), $answer, "positional: { c2.gist }"
}