Skip to content

Instantly share code, notes, and snippets.

@DefectingCat
Last active April 21, 2022 08:06
Show Gist options
  • Save DefectingCat/2c772bbd162345d9a7e83645e59fa1bb to your computer and use it in GitHub Desktop.
Save DefectingCat/2c772bbd162345d9a7e83645e59fa1bb to your computer and use it in GitHub Desktop.
Fibonacci
function fibonacci(num) {
let count = 0;
let result = [1, 1];
if (num <= 1) {
return result;
}
let n = num - 2;
for (let i = 0; i < n; i++) {
result.push(result[count] + result[count + 1]);
count++;
}
return result;
// let rs = result.reduce((a, b) => a + b);
// return rs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment