freeCodeCamp Challenge Guide: Ackermann function

Ackermann function


Solutions

Solution 1 (Click to Show/Hide)
function ack(m, n) {
   return (m === 0)
     ? n + 1
     : (m > 0 && n === 0)
       ? ack(m-1, 1)
       : ack(m-1, ack(m, n-1))
}

This solution writes the function in ternary format. Because the function is provided, all we need to do is to write the function to match exactly the equation provided.

1 Like