DEV Community

Discussion on: Let's Get Clever #1: Fibonacci Sequence

Collapse
 
grumpytechdude profile image
Alex Sinclair • Edited
const fib = (num) => {
  if (num == 0) return 0
  let x = 'I', y = ''
  for (let i = 0; i < num; i++) {
    if (i % 2 == 0)
      x += y
    else
      y += x

    return Math.max(x.length, y.length);
  }
}

Golly that was hard to do on mobile!
No need for maths or recursion here, let's use base 0 with a loop!

Collapse
 
codemouse92 profile image
Jason C. McDonald

Which language is this? I suspect Java, but I'm not sure at a glance.

This reminds me a bit of my alternating pair approach (in C), but it's strangely lovely. Nice work.

P.S. Did you mean for y += X to have an upper case X?

Collapse
 
grumpytechdude profile image
Alex Sinclair

Thank you! It's JavaScript, easiest thing for me on my phone. And I did not, thank you! I'll change it now.

I figure it could probably be made much fancier, but I'm not up for it right now!

Thread Thread
 
codemouse92 profile image
Jason C. McDonald

Shoot, bonus points for typing it on mobile at all, mate. ;-)