Travis build: 391
This commit is contained in:
@ -9,10 +9,13 @@ Uses a mathematical formula to calculate the length of the array required.
|
||||
```js
|
||||
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), []);
|
||||
return Array.from({ length: n }).reduce(
|
||||
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i),
|
||||
[]
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
fibonacciCountUntilNum(10) // 7
|
||||
fibonacciCountUntilNum(10); // 7
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user