Skip to content

Instantly share code, notes, and snippets.

@oieioi
Last active December 18, 2015 21:39
Show Gist options
  • Select an option

  • Save oieioi/5849137 to your computer and use it in GitHub Desktop.

Select an option

Save oieioi/5849137 to your computer and use it in GitHub Desktop.
class window.Fibonacci
# 初期条件
fibAry : [0,1]
# フィボナッチ数を返す
getFib : (n) =>
return @fibAry[n] if @fibAry[n]?
ret = (@getFib n - 1) + (@getFib n - 2)
@fibAry[n] = ret
return ret
# フィボナッチ数列を文字列として返す
getFibStr : (n, separator = ",") =>
@getFib n
ary = @fibAry.slice 0, n + 1
return ary.join separator
# フィボナッチ数列を返す
getFibAry : (n) =>
@getFib n
# 配列のコピーを返す
ary = @fibAry.slice 0, n + 1
return ary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment