Skip to content

Commit

Permalink
Added max and min.
Browse files Browse the repository at this point in the history
  • Loading branch information
Timofey Potapov committed Aug 21, 2024
1 parent 637775c commit 1ea279b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Revision history for e
1.28 - 2024-08-NN
=================

Added commands: max, min (from List::Util).
Updated pod.

=================
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,22 @@ Turn string into a [Mojo::File](https://metacpan.org/pod/Mojo%3A%3AFile) object.

$ perl -Me -e 'say r j f("hello.json")->slurp'

## Math Help

### max

Get the biggest number in a list.

$ perl -Me -e 'say max 2,4,1,3'
4

### min

Get the smallest number in a list.

$ perl -Me -e 'say max 2,4,1,3'
1

## Output

### say
Expand Down
38 changes: 38 additions & 0 deletions lib/e.pm
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ Turn string into a L<Mojo::File> object.
=cut

=head2 Math Help
=head3 max
Get the biggest number in a list.
$ perl -Me -e 'say max 2,4,1,3'
4
=head3 min
Get the smallest number in a list.
$ perl -Me -e 'say max 2,4,1,3'
1
=cut

=head2 Output
=head3 say
Expand Down Expand Up @@ -924,6 +942,26 @@ sub import {
Mojo::File::path( @_ );
},

######################################
# Math Help
######################################

max => sub {
if ( !$imported{$caller}{"List::Util"}++ ) {
require List::Util;
}

List::Util::max( @_ );
},

min => sub {
if ( !$imported{$caller}{"List::Util"}++ ) {
require List::Util;
}

List::Util::min( @_ );
},

######################################
# Output
######################################
Expand Down
14 changes: 14 additions & 0 deletions t/01-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ is
"cpuinfo",
"f - basename";

######################################
# Math Help
######################################

is
max(10,20,9,15),
20,
"max - sanity check";

is
min(10,20,9,15),
9,
"min - sanity check";

######################################
# Output
######################################
Expand Down

0 comments on commit 1ea279b

Please sign in to comment.