aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-207/james-smith/perl/ch-2.pl21
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-207/james-smith/perl/ch-2.pl b/challenge-207/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..bc06c9c57d
--- /dev/null
+++ b/challenge-207/james-smith/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+
+my @TESTS = (
+ [ [10,8,5,4,3], 4 ],
+ [ [25,8,5,3,3], 3 ],
+);
+
+is( h_index( @{$_->[0]} ), $_->[1] ) for @TESTS;
+is( h_index_2( @{$_->[0]} ), $_->[1] ) for @TESTS;
+is( h_index_3( @{$_->[0]} ), $_->[1] ) for @TESTS;
+
+done_testing();
+
+sub h_index { ( $_[$_]>$_) && return $_+1 for reverse 0..$#_ }
+sub h_index_2 { pop @_ while $_[-1] < @_; 0 + @_ }
+sub h_index_3 { ( $_[$_]>$_) || return $_ for 0..$#_; 0+@_ }