分享一个Fib数列实现 [reduce]
const fib = n => Array(n) .fill(0) .reduce(pre => [pre[1], pre[1] + pre[0]], [0, 1])[0] def fib(n): return reduce(lambda x, n: [x[1], x[0]+x[1]], range(n), [0, 1])[0] 性能也非常不错,迭代实现。从 Py 那边偷学的。 帅爆了有没有
Posted by Yinode Tuesday, October 16, 2018