diff options
| author | James Smith <js5@sanger.ac.uk> | 2023-03-12 08:43:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-12 08:43:51 +0000 |
| commit | 16e17609fb5fcdc9e7f09284bc8fbbca56b268cf (patch) | |
| tree | b892bf6c7b6c8d66e45765ee6f93f891ea8b2aea | |
| parent | aa6b154a8f7b5f643b566f3ee8913026998ce4b4 (diff) | |
| download | perlweeklychallenge-club-16e17609fb5fcdc9e7f09284bc8fbbca56b268cf.tar.gz perlweeklychallenge-club-16e17609fb5fcdc9e7f09284bc8fbbca56b268cf.tar.bz2 perlweeklychallenge-club-16e17609fb5fcdc9e7f09284bc8fbbca56b268cf.zip | |
Create ch-2.pl
| -rw-r--r-- | challenge-207/james-smith/perl/ch-2.pl | 21 |
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+@_ } |
