[solution] multiply fibonachi

main
Vasily Guzov 1 year ago
parent eed95e70ae
commit 6a7bf0c043

@ -0,0 +1,16 @@
// https://github.com/yangzj1992/FE-Questions/blob/master/codewars/5541f58a944b85ce6d00006a.Product%20of%20consecutive%20Fib%20numbers/Product%20of%20consecutive%20Fib%20numbers.md
export function fib(prod: number) {
let n = 0;
let nPlus = 1;
while (n * nPlus < prod) {
nPlus = n + nPlus;
n = nPlus - n;
}
return [n, nPlus, n * nPlus === prod];
}
// console.log(fib(55), [21, 34, true]);
console.log(fib(714), [21, 34, true]);
// console.log(fib(800), [34, 55, false]);
Loading…
Cancel
Save