Files
30-seconds-of-code/snippets_archive/fibonacciCountUntilNum.md
Angelos Chalaris 0425ebefe7 Archive, multitagging, cleanup
Cleaned up the current snippets for consistency and minor problems, added multiple tags to most of them, archived a few.
2018-01-05 16:33:54 +02:00

15 lines
372 B
Markdown

### fibonacciCountUntilNum
Returns the number of fibonnacci numbers up to `num`(`0` and `num` inclusive).
Use a mathematical formula to calculate the number of fibonacci numbers until `num`.
```js
const fibonacciCountUntilNum = num =>
Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
```
```js
fibonacciCountUntilNum(10); // 7
```