Run
Examples
var result = []; function fibonacci(n, res) { var a = 1, b = 1, sum; for (var i = 0; i < n; i++) { res.push(a); sum = a + b; a = b; b = sum; } } fibonacci(12, result); result.join(', ');
Console: