Skip to content

Commit 0c29bc7

Browse files
committed
Add anagram solution
1 parent dc0d2d1 commit 0c29bc7

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

exercises/anagram/.meta/exercise-data.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ tests: |-
99
example: |-
1010
sub match_anagrams {
1111
my ($input) = @_;
12-
return [];
12+
13+
return [
14+
grep {
15+
lc $_ ne lc $input->{subject}
16+
&& join( '', sort( split( //, lc $_ ) ) ) eq
17+
join( '', sort( split( //, lc $input->{subject} ) ) )
18+
} @{ $input->{candidates} }
19+
];
1320
}
1421
1522
stub: |-
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package Anagram;
22
use strict;
33
use warnings;
4-
use Exporter 'import';
5-
our @EXPORT_OK = qw(match_anagrams);
4+
use Exporter qw<import>;
5+
our @EXPORT_OK = qw<match_anagrams>;
66

77
sub match_anagrams {
88
my ($input) = @_;
9-
return [];
9+
10+
return [
11+
grep {
12+
lc $_ ne lc $input->{subject}
13+
&& join( '', sort( split( //, lc $_ ) ) ) eq
14+
join( '', sort( split( //, lc $input->{subject} ) ) )
15+
} @{ $input->{candidates} }
16+
];
1017
}
1118

1219
1;

exercises/anagram/Anagram.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package Anagram;
22
use strict;
33
use warnings;
4-
use Exporter 'import';
5-
our @EXPORT_OK = qw(match_anagrams);
4+
use Exporter qw<import>;
5+
our @EXPORT_OK = qw<match_anagrams>;
66

77
sub match_anagrams {
88
my ($input) = @_;

exercises/anagram/anagram.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use Test2::V0;
33
use JSON::PP;
44
use constant JSON => JSON::PP->new;
55

6-
use FindBin qw($Bin);
6+
use FindBin qw<$Bin>;
77
use lib $Bin, "$Bin/local/lib/perl5";
88

99
use Anagram qw(match_anagrams);
1010

1111
my @test_cases = do { local $/; @{ JSON->decode(<DATA>) }; };
1212
plan 15;
1313

14-
imported_ok qw(match_anagrams) or bail_out;
14+
imported_ok qw<match_anagrams> or bail_out;
1515

1616
for my $case (@test_cases) {
1717
is match_anagrams( $case->{input} ), $case->{expected},

0 commit comments

Comments
 (0)