LoginSignup
1
0

More than 5 years have passed since last update.

フィボナッチ数列演習js

Last updated at Posted at 2012-03-16
(function (scope) {

var _memo = [1, 1];

function fib(n) {
    var i;

    if (!_memo[n - 1]) {
        for (i = _memo.length; i < n; i += 1) {
            _memo[i] = _memo[i - 2] + _memo[i - 1];
        }
    }
    return _memo[n - 1];
}

scope.fib = fib;

}(this));
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0