aboutsummaryrefslogtreecommitdiff
path: root/challenge-262/barroff/perl/ch-1.pl
blob: b501411af50d39d5d5b3e359ebc0c931dffc93e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env perl

use v5.38;

sub max_positive_negative (@ints) {
    use List::Util qw /max/;
    max(
        scalar( grep( { $_ > 0 } @ints ) ),
        scalar( grep( { $_ < 0 } @ints ) )
    );
}

sub MAIN() {
    if (@ARGV) {

        #| Run on command line argument
        say max_positive_negative(@ARGV);
    }
    else {
        #| Run test cases
        use Test2::V0 qw( is plan );
        plan 3;
        is max_positive_negative( -3, 1, 2, -1, 3, -2, 4 ), 4,
          'works for (-3, 1, 2, -1, 3, -2, 4)';
        is max_positive_negative( -1, -2, -3, 1 ), 3,
          'works for (-1, -2, -3, 1)';
        is max_positive_negative( 1, 2 ), 2, 'works for (1, 2)';
    }
}

MAIN();