June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -3,3 +3,7 @@ sub mode (*@a) {
|
|||
my $max = %counts.values.max;
|
||||
return |%counts.grep(*.value == $max).map(*.key);
|
||||
}
|
||||
|
||||
# Testing with arrays:
|
||||
say mode [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17];
|
||||
say mode [1, 1, 2, 4, 4];
|
||||
|
|
|
|||
|
|
@ -1,2 +1,11 @@
|
|||
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
|
||||
);
|
||||
}
|
||||
|
||||
say mode [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17];
|
||||
say mode [1, 1, 2, 4, 4];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue