Averages/Mode: Difference between revisions

m
→‎{{header|Perl 6}}: slightly sub-optimal syntax
m (→‎{{header|Q}}: Fixed </lang>.)
m (→‎{{header|Perl 6}}: slightly sub-optimal syntax)
Line 2,180:
=={{header|Perl 6}}==
 
{{works with|Rakudo|20182019.03.1}}
<lang perl6>sub mode (*@a) {
my %counts := @a.Bag;
my $max = %counts.values.max;
return |%counts.grep(*.value == $max).map(*.key);
}
 
Line 2,200:
 
<lang perl6>sub mode (*@a) {
@a.Bag # count elements
return |(@a
.Bagclassify(*.value) # group elements with the #same count elements
.classifymax(*.valuekey) # groupget elementsgroup with the samehighest count
.maxvalue.map(*.key) ; # get groupelements within the highest countgroup
.value.map(*.key); # get elements in the group
);
}
 
2,392

edits