DEV Community

Discussion on: Daily Challenge #24 - Shortest Step

Collapse
 
avalander profile image
Avalander

Here's some recursion. I think it will work, but I'm not sure since I'm on my phone, I'll test it when I get home.

const steps = (n, acc = 0) =>
  n === 1
    ? acc
    : n % 2 === 0
    ? steps(n / 2, acc + 1)
    : steps(n - 1, acc + 1)