-
Code factorial=n=>n>1?n*factorial(n-1):1
Test Cases const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold=0; describe("factorial", function() { it("should test", function() { assert.strictEqual(factorial( 0 ), 1); assert.strictEqual(factorial( 1 ), 1); assert.strictEqual(factorial( 2 ), 2); assert.strictEqual(factorial( 3 ), 6); assert.strictEqual(factorial( 4 ), 24); assert.strictEqual(factorial( 5 ), 120); assert.strictEqual(factorial( 6 ), 720); assert.strictEqual(factorial( 7 ), 5040); assert.strictEqual(factorial( 8 ), 40320); assert.strictEqual(factorial( 9 ), 362880); assert.strictEqual(factorial( 10 ), 3628800); }); });
Output:
-
Code factorial=n=>{for(x=i=1;i<n;)x*=++i;return x}- factorial=n=>n>1?n*factorial(n-1):1
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}