RosettaCodeData/Task/Averages-Simple-moving-average/Brat/averages-simple-moving-average-2.brat
2014-04-02 16:56:35 +00:00

17 lines
267 B
Text

sma = { period |
list = []
{ num |
true? list.length >= period
{ list.deq }
list << num
list.reduce(:+) / list.length
}
}
sma3 = sma 3
sma5 = sma 5
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1].each { n |
p n, " - SMA3: ", sma3(n), " SMA5: ", sma5(n)
}