for anyone familiar with the Fibonacci sequence I wrote this function using a recursive algorithm that was on a bit of a whim. It is indeed working but I can not wrap my head around how. If anyone can explain this to me or point me to a resource I would be super appreciative
function fibonacciRecursive(n) {
let startPoint = 0;
let secondPoint = 1;
let indexVal = 0;
if (n === 0) {
return startPoint;
}
if (n === 1) {
return secondPoint;
}
indexVal = startPoint + secondPoint;
startPoint = secondPoint;
secondPoint = indexVal;
return indexVal * fibonacciRecursive(n)
}
// fibonacci seq => 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144