Last active
August 29, 2015 13:55
-
-
Save colomon/8689734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub simple-moving-average(Int $P where * > 0) { | |
-> Real $x { | |
state @a; | |
@a.push($x); | |
@a.shift if @a > $P; | |
([+] @a) / @a; | |
} | |
} | |
my &ma3 = simple-moving-average(3); | |
say &ma3(1); | |
say &ma3(1); | |
say &ma3(2); | |
say &ma3(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't even need the & sigil to invoke the sub -- this works too:
say ma3(1);