diff options
| -rw-r--r-- | challenge-073/cheok-yin-fung/perl/ch-2.pl | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/challenge-073/cheok-yin-fung/perl/ch-2.pl b/challenge-073/cheok-yin-fung/perl/ch-2.pl index d814efcaf0..071e9f4dea 100644 --- a/challenge-073/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-073/cheok-yin-fung/perl/ch-2.pl @@ -8,12 +8,15 @@ # If none found then use 0. # Usage: ch-2.pl @A # for input: (2, 2, 2, 3, 2, 4), should it be (0, 0, 0, 2, 0, 2) or (0, 2, 2, 2, 2, 2)...? -# Or, the task statement should be modified as: ... smallest and smaller element to the left of ... +# I choose the former here. +# Or, the task statement should be clarified as: +# ... smallest element to the left of ..., while that element is smaller than the indexed number +# (verbose...) use strict; use warnings; -#use Test::More tests => 5; +#use Test::More tests => 6; my @A; @@ -29,10 +32,11 @@ sub leastneigh { push @smallkids, 0; $youngest = $num; } - else { + elsif ($num > $youngest) { # $num > $youngest push @smallkids, $youngest; + } else { # $num == $youngest + push @smallkids, 0; } - } return [@smallkids]; } @@ -40,6 +44,7 @@ sub leastneigh { print join " ", @{ leastneigh([@A]) }; print "\n"; + =pod is_deeply( leastneigh([7, 8, 3, 12, 10]), [0, 7, 0, 3, 3], "example1 provided") ; |
