Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Averages-Mode/Elena/averages-mode.elena
Normal file
37
Task/Averages-Mode/Elena/averages-mode.elena
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import system'routines;
|
||||
import system'collections;
|
||||
import extensions;
|
||||
|
||||
extension op
|
||||
{
|
||||
get Mode()
|
||||
{
|
||||
var countMap := Dictionary.new(0);
|
||||
self.forEach:(item)
|
||||
{
|
||||
countMap[item] := countMap[item] + 1
|
||||
};
|
||||
|
||||
countMap := countMap.Values.sort:(p,n => p > n);
|
||||
|
||||
var max := countMap.FirstMember;
|
||||
|
||||
^ countMap
|
||||
.filterBy:(kv => max.equal(kv.Value))
|
||||
.selectBy:(kv => kv.Key)
|
||||
.toArray()
|
||||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
{
|
||||
var array1 := new int[]{1, 1, 2, 4, 4};
|
||||
var array2 := new int[]{1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17};
|
||||
var array3 := new object[]{1, "blue", 2, 7.5r, 5, "green", "red", 5, 2, "blue", "white"};
|
||||
|
||||
console
|
||||
.printLine("mode of (",array1.asEnumerable(),") is (",array1.Mode,")")
|
||||
.printLine("mode of (",array2.asEnumerable(),") is (",array2.Mode,")")
|
||||
.printLine("mode of (",array3.asEnumerable(),") is (",array3.Mode,")")
|
||||
.readChar()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue