Files
30-seconds-of-code/snippets_archive/fibonacciCountUntilNum.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

402 B

title, tags
title tags
fibonacciCountUntilNum math,beginner

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.

const fibonacciCountUntilNum = num =>
  Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
fibonacciCountUntilNum(10); // 7