This was my go at it.

```
function fibFinder(n) {
// Write your code here
let count = 1
let first = 0
let second = n === 0 ? 0 : 1
while (count < n) {
count ++
let newNum = first + second
first = second
second = newNum
}
return second
}
console.log(fibFinder(0))
// Leave this so that we can test your code:
module.exports = fibFinder;
```

function fibFinder(n) {

// Write your code here

let num1 = 0;

let num2 = 1;

let result = n;

for(let i = 2; i <= n; i++){

result = num1 + num2;

num1 = num2;

num2 = result;

}

return result;

}

console.log(fibFinder(6))

// Leave this so that we can test your code:

module.exports = fibFinder;

The only correct way to do this.

That is an indefensible statement and could not be farther from the truth.

While I enjoy condensing functions into a single line of code just to see if it’s possible, very seldom are one-liners the most efficient in terms of time or space complexity.

Do we want a list of Fibonacci numbers, or do we want an answer to the question, what is the Nth term in the sequence? Think on this. What solution code is the best fit?

If the Nth term is what we are after then it makes sense to just run out the sequence to that term and call it a day. There will be very little memory use and we will have our answer.

Of course we can bring out the root five solution, but that’s paper not computer. Let’s not blur the lines. Still, I love paper and pencil.

Hi, here is my solution

```
function fibFinder(n) {
let a = 0;
let b = 1;
for(i = 0; i < n; i++) {
[a, b] = [b, a + b];
}
return a;
}
```

function fibFinder(n) {

if (n < 0) {

return ‘Index must be greater than or equal to zero’

} else if (n <= 1) {

return n

}

let arr = [0, 1];

while (arr.length < (n + 1)) {

arr[arr.length] = arr[arr.length - 1] + arr[arr.length -2]

}

return arr[n]

}

console.log(fibFinder(6))

// Leave this so that we can test your code:

module.exports = fibFinder;

- Recursion will keep a lot of memory in call stack until it release stack after end. More and more with any next step
- Recursion limited 5000-100000 deep levels depending on engine. Therefore, it is impossible to calculate, for example, 10000th Fibonacci number in Chrome browser. But it is not so important because fibFinder(1477) = Infinity
- This approach 5x+ slower than straightforward method with values swapping

This approach 5x slower than fastest

My like to your solution. It will be 3x+ faster with simple swapping.

```
function fibFinder(n) {
let a = 0;
let b = 1;
let fib;
for (let i = 0; i < n; i++) {
fib = a + b;
a = b;
b = fib;
}
return a;
}
```