commit 929d702961331f0784d840303815ba01627532c6 parent 004ed5852a0864bc247c7704b638bb1d7e0848fb Author: Samir Parikh <noreply@samirparikh.com> Date: Sat, 27 Nov 2021 17:18:33 +0000 get invalid strand test to pass Diffstat:
M | nucleotide-count/NucleotideCount.pm | | | 15 | ++++++++++++++- |
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/nucleotide-count/NucleotideCount.pm b/nucleotide-count/NucleotideCount.pm @@ -13,7 +13,7 @@ sub count_nucleotides { 'T' => 0 ); if ($strand =~ /[^ACGT]/) { - return "Invalid nucleotide in strand"; + die "Invalid nucleotide in strand"; } else { foreach (split //, $strand) { $count{$_}++; @@ -22,4 +22,17 @@ sub count_nucleotides { return \%count; } +# +# Better solution from pnyman at Exercism.org: +# https://exercism.org/tracks/perl5/exercises/nucleotide-count/solutions/pnyman +# +# sub count_nucleotides { +# my ($strand) = @_; +# die "Invalid nucleotide in strand" if grep {/[^ACGT]/} $strand; +# my %nucleotides = map { $_ => 0 } qw( A C G T ); +# map { $nucleotides{$_}++ } split //, $strand; +# \%nucleotides; +# } +# + 1;