Anonymous user
Averages/Simple moving average: Difference between revisions
→{{header|zkl}}: re-write to match task description
(Added Kotlin) |
(→{{header|zkl}}: re-write to match task description) |
||
Line 4,212:
=={{header|zkl}}==
if(P<ns.append(n.toFloat()).len()) ns.del(0);▼
<lang zkl>zkl: T(1,2,3,4,5,5,4,3,2,1).apply(SMA)▼
L(1,1.5,2,3,4,4.66667,4.66667,4,3,2)▼
L(1,1.5,2,2.5,3,3.8,4.2,4.2,3.8,3)</lang>▼
<lang zkl>fcn SMA(P){
fcn(n,ns,P){
sz:=ns.
ns.sum(0.0)/P;
}.fp1(List.createLong(P+1),P) // pre-allocate a list of length P+1
}</lang>
fp1 creates a partial application fixing the (in this case) the second and third
parameters
{{out}}
<pre>
</pre>
|