update snippets 32-47

This commit is contained in:
Stefan Feješ
2017-12-25 14:10:38 +01:00
committed by Agamemnon Zorbas
parent 3994e12792
commit 0001ff4dcb
16 changed files with 71 additions and 27 deletions

View File

@ -10,6 +10,9 @@ Uses a mathematical formula to calculate the length of the array required.
const fibonacciUntilNum = num => {
let n = Math.ceil(Math.log(num * Math.sqrt(5) + 1 / 2) / Math.log((Math.sqrt(5) + 1) / 2));
return Array.from({ length: n}).reduce((acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i), []);
};
// fibonacciUntilNum(15) -> [0,1,1,2,3,5,8,13]
}
```
```js
fibonacciCountUntilNum(10) // 7
```