1.6 KiB
1.6 KiB
title | id | challengeType | forumTopicId |
---|---|---|---|
Ackermann function | 594810f028c0303b75339acf | 5 | 302223 |
Description
Instructions
Tests
tests:
- text: <code>ack</code> should be a function.
testString: assert(typeof ack === 'function');
- text: <code>ack(0, 0)</code> should return 1.
testString: assert(ack(0, 0) === 1);
- text: <code>ack(1, 1)</code> should return 3.
testString: assert(ack(1, 1) === 3);
- text: <code>ack(2, 5)</code> should return 13.
testString: assert(ack(2, 5) === 13);
- text: <code>ack(3, 3)</code> should return 61.
testString: assert(ack(3, 3) === 61);
Challenge Seed
function ack(m, n) {
}
Solution
function ack(m, n) {
return m === 0 ? n + 1 : ack(m - 1, n === 0 ? 1 : ack(m, n - 1));
}