All files / algorithms/lib fib.ts

0% Statements 0/10
100% Branches 1/1
100% Functions 1/1
0% Lines 0/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17                                 
// 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]);