Skip to content

Commit 787bd96

Browse files
authored
Add Fibonacci in Moonscript (#4496)
* figured our3/8 not valid inputs, unsure hwo to check if input param is num * how did i figure that out omg * more professional message completed all 8 testcase
1 parent 348f5d4 commit 787bd96

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- fibonacci function
2+
fibonacci = (n) ->
3+
-- set up a, b, for i until n, print "i: n" then update a & b as the fibonacci sequence
4+
a, b = 1, 1
5+
for i = 1, n
6+
print "#{i}: #{a}"
7+
a, b = b, a + b
8+
9+
-- main
10+
-- check if arg params are numbers and are greater than 0
11+
if arg[1] and tonumber(arg[1]) ~= nil and tonumber(arg[1]) >= 0
12+
fibonacci tonumber(arg[1])
13+
-- else, return usage error msg
14+
else
15+
print "Usage: please input the count of fibonacci numbers to output"
16+

0 commit comments

Comments
 (0)