Averages/Mode: Difference between revisions
Content added Content deleted
(Initial FutureBasic task solution added) |
(Added Easylang) |
||
Line 939: | Line 939: | ||
maxCount := maxCount.max(newCount)</syntaxhighlight> |
maxCount := maxCount.max(newCount)</syntaxhighlight> |
||
In for loops, each key and value from the collection are [[Pattern Matching|pattern matched]] against the specified <code><var>key pattern</var> => <var>value pattern</var></code>. In "<code>for v => ==maxCount in counts</code>", the <code>==</code> is a pattern-match operator which fails unless the value examined is equal to the specified value; so this selects only the input values (keys in <code>counts</code>) whose counts are equal to the maximum count. |
In for loops, each key and value from the collection are [[Pattern Matching|pattern matched]] against the specified <code><var>key pattern</var> => <var>value pattern</var></code>. In "<code>for v => ==maxCount in counts</code>", the <code>==</code> is a pattern-match operator which fails unless the value examined is equal to the specified value; so this selects only the input values (keys in <code>counts</code>) whose counts are equal to the maximum count. |
||
=={{header|EasyLang}}== |
|||
<syntaxhighlight> |
|||
proc modes . in[] r[] . |
|||
r[] = [ ] |
|||
for v in in[] |
|||
for i to len vals[] |
|||
if v = vals[i] |
|||
cnt[i] += 1 |
|||
max = higher cnt[i] max |
|||
break 1 |
|||
. |
|||
. |
|||
vals[] &= v |
|||
cnt[] &= 0 |
|||
. |
|||
for i to len cnt[] |
|||
if cnt[i] = max |
|||
r[] &= vals[i] |
|||
. |
|||
. |
|||
. |
|||
in[] = [ 1 3 6 6 6 6 7 7 12 12 17 ] |
|||
modes in[] mods[] |
|||
print mods[] |
|||
in[] = [ 1 1 2 4 4 ] |
|||
modes in[] mods[] |
|||
print mods[] |
|||
</syntaxhighlight> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |