let array = [0, 1, 1];
const fibonacciSequence = (number) => {
if (number < 2) {
return array[number];
} else if (number == 2) {
console.log(array.length-1);
console.log((array[array.length-1]));
// return (array[array.length - 1]);
return (array[array.length-1]); // why does this return statement give undefined???
}
else {
array.push(array[array.length - 1] + array[array.length - 2]);
fibonacciSequence(number - 1);
}
};
console.log(fibonacciSequence(3));
Expected result: 2..