Skip to content

Commit ccb04d9

Browse files
committed
Add anagram solution
1 parent e503249 commit ccb04d9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
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: |-

exercises/anagram/.meta/solutions/Anagram.pm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ 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;

0 commit comments

Comments
 (0)