diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2024-07-08 06:39:29 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2024-07-08 06:39:29 +0000 |
| commit | ddf1af8b36c77f9ebe1175fdfa711505f1264c0a (patch) | |
| tree | 0f3693b110fc9b7b33aa55222482d64d60c51501 | |
| parent | 6066e198454df3c3db2740708c880aa48d27a25b (diff) | |
| download | perlweeklychallenge-club-ddf1af8b36c77f9ebe1175fdfa711505f1264c0a.tar.gz perlweeklychallenge-club-ddf1af8b36c77f9ebe1175fdfa711505f1264c0a.tar.bz2 perlweeklychallenge-club-ddf1af8b36c77f9ebe1175fdfa711505f1264c0a.zip | |
Task 1, shorter code using "singleton()"
| -rwxr-xr-x | challenge-277/perlboy1967/perl/ch1.pl | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/challenge-277/perlboy1967/perl/ch1.pl b/challenge-277/perlboy1967/perl/ch1.pl index 1ced4da647..0cfaa4bcb2 100755 --- a/challenge-277/perlboy1967/perl/ch1.pl +++ b/challenge-277/perlboy1967/perl/ch1.pl @@ -23,14 +23,12 @@ use common::sense; use Test2::V0 qw(-no_srand); +use List::AllUtils qw(singleton); + sub countCommon { - my ($arW1,$arW2,%f1,%f2,%fc) = @_; - map { $f1{$_}++ } @$arW1; - map { $f2{$_}++ } @$arW2; - map { $fc{$_}++ } - (grep { $f1{$_} == 1 } keys %f1), - (grep { $f2{$_} == 1 } keys %f2); - scalar grep { $_ == 2 } values %fc; + my %f; + $f{$_}++ for (singleton(@{$_[0]}),singleton(@{$_[1]})); + grep { $_ == 2 } values %f; } is(countCommon([qw{Perl is my friend}], |
