Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję0
Why is there a warning
1 Odpowiedź
+ 9
Devin because you have an expression that essentially its result is undefined. it's because you’re changing a variable more than once in it.
return n * fibonacci(--n);
you both multiplying n by a number (f(x)) and at the same time trying to decrement it (--n, result stroes in n, but there's another n also for multiplying n * f(x)). it has to decrement n and get the result of f(n), but also not decrement it because there is a multiplication by the current value of same variable n.
so it's confusing to compiler.
it doesn't matter to pass --n or n-1, both have same value for f(x) but in second case you haven't modify n twice. so just do:
return n * fibonacci(n-1);