Averages/Mode: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Changed to Wren S/H)
imported>Arakov
 
Line 990: Line 990:


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0:
ELENA 6.x:
<syntaxhighlight lang="elena">import system'routines;
<syntaxhighlight lang="elena">import system'routines;
import system'collections;
import system'collections;
Line 1,000: Line 1,000:
{
{
var countMap := Dictionary.new(0);
var countMap := Dictionary.new(0);
self.forEach:(item)
self.forEach::(item)
{
{
countMap[item] := countMap[item] + 1
countMap[item] := countMap[item] + 1
};
};
countMap := countMap.Values.sort:(p,n => p > n);
countMap := countMap.Values.sort::(p,n => p > n);
var max := countMap.FirstMember;
var max := countMap.FirstMember;
^ countMap
^ countMap
.filterBy:(kv => max.equal(kv.Value))
.filterBy::(kv => max.equal(kv.Value))
.selectBy:(kv => kv.Key)
.selectBy::(kv => kv.Key)
.toArray()
.toArray()
}
}
Line 1,018: Line 1,018:
public program()
public program()
{
{
var array1 := new int[]{1, 1, 2, 4, 4};
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 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"};
var array3 := new object[]{1, "blue", 2, 7.5r, 5, "green", "red", 5, 2, "blue", "white"};
console
console
.printLine("mode of (",array1.asEnumerable(),") is (",array1.Mode,")")
.printLine("mode of (",array1.asEnumerable(),") is (",array1.Mode,")")
.printLine("mode of (",array2.asEnumerable(),") is (",array2.Mode,")")
.printLine("mode of (",array2.asEnumerable(),") is (",array2.Mode,")")
.printLine("mode of (",array3.asEnumerable(),") is (",array3.Mode,")")
.printLine("mode of (",array3.asEnumerable(),") is (",array3.Mode,")")
.readChar()
.readChar()
}</syntaxhighlight>
}</syntaxhighlight>
{{out}}
{{out}}