aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-27 18:59:49 +0100
committerGitHub <noreply@github.com>2024-04-27 18:59:49 +0100
commitef93ada78078606b9334dcc3584ffdfbc981e4ba (patch)
treed9e31b5208dfe5e099ed99397969a9fb7cadbba0
parentf4e91bf8742669d75833586dff870947f4e89638 (diff)
parent986d18b253d16bca41cc47f03f39721af1694fd4 (diff)
downloadperlweeklychallenge-club-ef93ada78078606b9334dcc3584ffdfbc981e4ba.tar.gz
perlweeklychallenge-club-ef93ada78078606b9334dcc3584ffdfbc981e4ba.tar.bz2
perlweeklychallenge-club-ef93ada78078606b9334dcc3584ffdfbc981e4ba.zip
Merge pull request #9995 from lancew/branch-for-challenge-266
Task One, Perl
-rw-r--r--challenge-266/lance-wicks/perl/lib/UCW.pm38
-rw-r--r--challenge-266/lance-wicks/perl/t/01-ucw.t24
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-266/lance-wicks/perl/lib/UCW.pm b/challenge-266/lance-wicks/perl/lib/UCW.pm
new file mode 100644
index 0000000000..58f81a66b7
--- /dev/null
+++ b/challenge-266/lance-wicks/perl/lib/UCW.pm
@@ -0,0 +1,38 @@
+package UCW;
+
+=pod
+
+> A word is uncommon if it appears exactly once
+> in one of the sentences and doesn’t appear in
+> other sentence.
+
+Example 1
+
+Input: $line1 = 'Mango is sweet'
+ $line2 = 'Mango is sour'
+Output: ('sweet', 'sour')
+=cut
+
+sub words {
+ my $self = shift;
+ my $line1 = shift;
+ my $line2 = shift;
+
+ my @line1_words = split( /\s+/, $line1 );
+ my @line2_words = split( /\s+/, $line2 );
+
+ my %words;
+ for ( @line1_words, @line2_words ) {
+ $words{$_}++;
+ }
+
+ my @words;
+ for ( keys %words ) {
+ if ( $words{$_} == 1 ) {
+ push @words, $_;
+ }
+ }
+ return [ sort @words ];
+}
+
+1; \ No newline at end of file
diff --git a/challenge-266/lance-wicks/perl/t/01-ucw.t b/challenge-266/lance-wicks/perl/t/01-ucw.t
new file mode 100644
index 0000000000..270d4039b4
--- /dev/null
+++ b/challenge-266/lance-wicks/perl/t/01-ucw.t
@@ -0,0 +1,24 @@
+use Test2::V0 -target => 'UCW';
+
+subtest 'Example 1' => sub {
+ my $line1 = 'Mango is sweet';
+ my $line2 = 'Mango is sour';
+
+ is $CLASS->words( $line1, $line2 ), [ 'sour', 'sweet' ];
+};
+
+subtest 'Example 2' => sub {
+ my $line1 = 'Mango Mango';
+ my $line2 = 'Orange';
+
+ is $CLASS->words( $line1, $line2 ), ['Orange'];
+};
+
+subtest 'Example 3' => sub {
+ my $line1 = 'Mango is Mango';
+ my $line2 = 'Orange is Orange';
+
+ is $CLASS->words( $line1, $line2 ), [];
+};
+
+done_testing; \ No newline at end of file