diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2023-01-08 22:00:18 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2023-01-08 22:00:18 +0000 |
| commit | e51df0e10c172a7ece78a5f15e5aada7b48b61a5 (patch) | |
| tree | c8f7606d9e8b9a756c7874e5a76dfcb5de6ea71b | |
| parent | 119b00cc801208529bb4af2a2d296a4c4d7fff99 (diff) | |
| download | perlweeklychallenge-club-e51df0e10c172a7ece78a5f15e5aada7b48b61a5.tar.gz perlweeklychallenge-club-e51df0e10c172a7ece78a5f15e5aada7b48b61a5.tar.bz2 perlweeklychallenge-club-e51df0e10c172a7ece78a5f15e5aada7b48b61a5.zip | |
Task 1 - Add max() caching outsize grep {} loop
| -rwxr-xr-x | challenge-198/perlboy1967/perl/ch-1.pl | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/challenge-198/perlboy1967/perl/ch-1.pl b/challenge-198/perlboy1967/perl/ch-1.pl index 7f4048ee66..ca0b9d5cc3 100755 --- a/challenge-198/perlboy1967/perl/ch-1.pl +++ b/challenge-198/perlboy1967/perl/ch-1.pl @@ -29,9 +29,10 @@ use Test::More; sub maxGap { return 0 if (scalar @_ < 2); - my @l = slide { $b - $a } sort { $a <=> $b } @_; + my @deltas = slide { $b - $a } sort { $a <=> $b } @_; + my $max = max(@deltas); - return scalar grep { $_ == max(@l) } @l; + return scalar grep { $_ == $max } @deltas; } |
