Anonymous user
Averages/Mode: Difference between revisions
→{{header|Perl 6}}: add version without temporaries
(→{{header|Perl 6}}: update code to be idiomatic rather than literally translated Perl 5, and use object identity instead of string comparison) |
(→{{header|Perl 6}}: add version without temporaries) |
||
Line 1,962:
(4 1)
</pre>
Alternatively, a version that uses a single method chain with no temporary variables:
<lang perl6>sub mode (*@a) {=
return |(@a
.Bag # count elements
.classify(*.value) # group elements with the same count
.max(*.key) # get group with the highest count
.value.map(*.key); # get elements in the group
);
}</lang>
=={{header|Phix}}==
|