You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
491 B
TypeScript
17 lines
491 B
TypeScript
// 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]);
|