Jump to content

Averages/Mode: Difference between revisions

Initial FutureBasic task solution added
Tag: Manual revert
(Initial FutureBasic task solution added)
Line 1,401:
As of the 2022-07-31 release of Frink, the function can be rewritten as:
<syntaxhighlight lang="frink">modes[vals] := mostCommon[vals]@0</syntaxhighlight>
 
=={{header|FutureBasic}}==
FB has a native function for an array of mode averages.
<syntaxhighlight lang="futurebasic">
local fn ModeAverage( arguments as CFArrayRef ) as CFStringRef
ExpressionRef expRef = fn ExpressionForFunction( @"mode:", @[fn ExpressionForConstantValue( arguments )] )
CFArrayRef modeArray = fn ExpressionValueWithObject( expRef, NULL, NULL )
CFNumberRef number
CFMutableStringRef modeStr = fn MutableStringNew
for number in modeArray
MutableStringAppendFormat( modeStr, @"value = %@\n", number )
next
end fn = modeStr
 
print fn ModeAverage( @[@1, @3, @6, @6, @6, @6, @7, @7, @12, @12, @12, @12, @17] )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
value = 6
value = 12
</pre>
 
 
=={{header|GAP}}==
717

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.