Categories
Generates a Fibonacci sequence of a given length.
Contributed by @itsbrunodev
function fibonacci(n) { const seq = [0, 1]; for (let i = 2; i < n; i++) { seq.push(seq[i - 1] + seq[i - 2]); } return seq.slice(0, n); }
fibonacci(10); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]