aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKUEPPO <tcheukueppo@tutanota.com>2022-11-07 01:20:46 +0100
committerGitHub <noreply@github.com>2022-11-07 01:20:46 +0100
commit2bbf531aeb7f75db241aba108b1eda2ebb54f7eb (patch)
treec10162f28666960e45e8806b874c0b2cfba88a95
parentb7510387a2c6fc2aedd4ae68d19ad054e880b417 (diff)
downloadperlweeklychallenge-club-2bbf531aeb7f75db241aba108b1eda2ebb54f7eb.tar.gz
perlweeklychallenge-club-2bbf531aeb7f75db241aba108b1eda2ebb54f7eb.tar.bz2
perlweeklychallenge-club-2bbf531aeb7f75db241aba108b1eda2ebb54f7eb.zip
ch-1.pl pwc-189
-rw-r--r--challenge-189/kueppo-wesley/Perl/ch-1.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-189/kueppo-wesley/Perl/ch-1.pl b/challenge-189/kueppo-wesley/Perl/ch-1.pl
new file mode 100644
index 0000000000..367b27cc00
--- /dev/null
+++ b/challenge-189/kueppo-wesley/Perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use List::Util qw/ first /;
+
+sub find_greater_char {
+ my ( $array, $target ) = @_;
+
+ return ( first { $_ gt $target } sort { $a cmp $b } @$array ) // $target;
+}
+
+my $expected = [ qw/e c r c v/ ];
+my @samples = (
+ [ [ qw/e m u g/ ], q/b/ ],
+ [ [ qw/d c e f/ ], q/a/ ],
+ [ [ qw/j a r/ ], q/o/ ],
+ [ [ qw/d c a f/ ], q/a/ ],
+ [ [ qw/t g a l/ ], q/v/ ]
+);
+
+is_deeply( $expected, [ map { find_greater_char( @$_ ) } @samples ], 'found the correct chars?' );
+
+done_testing( 1 );