I read about recursion and tried to apply it to my algorithm and succeed
I first made a function which makes fibonacci stuff and then put it in another method - the main method required by FCC/
Here’s my code:
function sumFibs(num) {
// Function to make fibonacci and return the sum of odd numbers
// that meet the requirements
function fib(startX, startY, oddSum,num) {
// check if the nuber is odd and meet the requirements to
// add to the sum
if (startX % 2 !== 0 && startX <= num) {
oddSum += startX;
}
var sum = startX + startY;
// temp for storing startY
var buff = startY;
startY = sum;
startX = buff;
// make the fibonacci loop and don't exceed memory
if (startX + startY < num * num) {
return(fib(startX,startY,oddSum,num));
}
return oddSum;
// body...
}
// the starting numbers are 1 and 1 instead of 0 for convenient purposes
return fib(1,1,0,num);
}
return sumFibs(4);
`
`
Is there somthing I can improve?