From ead9efa1f35d00ba91dcc50f157b5635a246bc32 Mon Sep 17 00:00:00 2001 From: Likeshshankar Date: Sat, 19 Oct 2024 09:09:09 +0530 Subject: [PATCH] Update Ackermann.js --- Algorithms/Ackermann/Ackermann.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Algorithms/Ackermann/Ackermann.js b/Algorithms/Ackermann/Ackermann.js index 3597bbbe3..dae8273d4 100644 --- a/Algorithms/Ackermann/Ackermann.js +++ b/Algorithms/Ackermann/Ackermann.js @@ -1,10 +1,10 @@ -n = 2; -m = 3; + let n = 2; +let m = 3; function ackermann(n, m) { - if (n == 0) return m + 1; - if (m == 0) return ackermann(n - 1, 1); + if (n === 0) return m + 1; + if (n > 0 && m === 0) return ackermann(n - 1, 1); return ackermann(n - 1, ackermann(n, m - 1)); } -console.log(`ackermann(${n},${m}) = `, ack(n, m)); +console.log(`ackermann(${n}, ${m}) = `, ackermann(n, m));