in reply to Re^4: add missing elements and remove duplicates....and some more questions.
in thread add missing elements and remove duplicates....and some more questions.
Another big point: What you name variables DOES matter. @unique does not really describe what that is (these are not the uniques of the original array, this is the consecutive range. I would suggest @consecutive as an alternative name.
Update: Instead of "do_it_all", perhaps "conseq_range" or similar would be better?use strict; use warnings; my @arr = (1,2,2,3,4,6); sub do_it_all { my $biggest = $_[0]; my $smallest = $_[0]; foreach my $num (@_) { $biggest = $num if ($num > $biggest); $smallest = $num if ($num < $smallest); } print "\$smallest = $smallest\t\$biggest = $biggest\n"; my @consecutive = ($smallest..$biggest); print "@consecutive\n"; } do_it_all(@arr); __END__ $smallest = 1 $biggest = 6 1 2 3 4 5 6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: add missing elements and remove duplicates....and some more questions.
by pritesh_ugrankar (Monk) on Apr 25, 2017 at 18:48 UTC |