function iterFib(n) {let last = 1;let nextLast = 1;let result = 1;for (let i = 2; i < n; ++i) {result = last + nextLast;nextLast = last;last = result;}return result;}
function test(func,n){let start = new Date().getTime();//起始时间let res = func(n);//执行待测函数document.write(‘<br>’+’当n=’+n+’高级web前端开发的时候 ’+res+'<br>’);let end = new Date().getTime();//结束时间return (end – start)+”ms”;//返回函数执行需要时间}let time = test(iterFib,3);console.log(time)
斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233高级web前端开发,377高级web前端开发,610高级web前端开发,987,1597,2584,4181,6765,10946,17711,28657,46368……..
这个数列从第3项开始,每一项都等于前两项之和。