Last active
December 18, 2015 21:39
-
-
Save oieioi/5849137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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